1
게시글을 가지고 친숙한 서어를 만들려고합니다. 그래서 내가 지금까지 만든 것은이에 내 내 BlogController 내가 오류를RouteServiceProvider에서 쿼리를 찾을 수 없습니다.
ModelNotFoundException있어 포스트 http://example.com/slug-from-database로 이동
public function show(Post $post){ return view("blog.show", compact('post')); }
에서
RouteServiceProvider
namespace App\Providers; use Illuminate\Support\Facades\Route; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use App\Post; class RouteServiceProvider extends ServiceProvider { /** * This namespace is applied to your controller routes. * * In addition, it is set as the URL generator's root namespace. * * @var string */ protected $namespace = 'App\Http\Controllers'; /** * Define your route model bindings, pattern filters, etc. * * @return void */ public function boot() { parent::boot(); Route::bind('post', function($slug){ return Post::published()->where('slug')->first(); }); }
이 Builder.php 라인 426 :
[App \ Post] 모델에 대한 쿼리 결과가 없습니다.
이 오류가 발생하는 이유는 무엇입니까?
Route::bind('post', function($slug){
return Post::published()->where('slug')->first();
});
변경이 같은 쿼리를하고 그것을 작동합니다 :
그냥 확인하고 싶은 당신이라는 모델을 가지고 할 'App \ Post'의 네임 스페이스를 가진'Post'? – Spholt
예, 있습니다. 나는 또한 그것을 게시 할 수 있지만 문제는 여기에 관련이 없습니다. –
서비스 제공자의 네임 스페이스를 지정하는 것이'App \ Http \ Controllers \ Post'에서'Post' 모델을 찾으려고 할 수 있다는 것을 알았습니다. 오류 출력을 더 이상 나타내지 않으면 알기가 조금 어렵습니다. 이것은 약간 긴 촬영입니다. – Spholt