Reputation: 2329
I was following a tutorial where i view single post but for some reason it see not found expection i don't know what is missing
NotFoundHttpException in RouteCollection.php line 161:
I am trying to access the route through this URL
http://domain.app/admin/blog/post/2&admin
View Path
views -> admin -> blog -> single.blade.php
Route
Route::group(['prefix' => '/admin'], function(
Route::get('/blog/post/{post_id}&{$end}', [
'uses' => 'PostController@getSinglePost',
'as' => 'admin.blog.post'
]);
});
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use App\Catgory;
class PostController extends Controller {
public function getSinglePost($post_id, $end = 'frontend') {
$post = Post::find($post_id);
if(!$post) {
return redirect()->route('blog.index')->with(['fail' => 'Post not found']);
}
return view ($end, '.blog.single', ['post' => $post]);
}
}
Upvotes: 0
Views: 2560
Reputation: 7617
Could you try it this way?
ROUTE
<?php
// SHOULD MATCH SOMETHING LIKE: /admin/blog/post/1/admin
// OR: /admin/blog/post/1/frontend
Route::group(['prefix' => '/admin'], function(
Route::get('/blog/post/{post_id}/{end}', [
'uses' => 'PostController@getSinglePost',
'as' => 'admin.blog.post'
]);
});
CONTROLLER
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use App\Catgory;
class PostController extends Controller {
public function getSinglePost($post_id, $end = 'frontend') {
$post = Post::find($post_id);
if(!$post) {
return redirect()->route('blog.index')->with(['fail' => 'Post not found']);
}
// YOU ARE CONCATENATING SO NO NEED FOR COMMA...
return view($end . '.blog.single', ['post' => $post]);
}
}
Upvotes: 1
Reputation: 2096
Try / instead of &...
Route::group(['prefix' => '/admin'], function(
Route::get('/blog/post/{post_id}/{end}', [
'uses' => 'PostController@getSinglePost',
'as' => 'admin.blog.post'
]);
});
AND your url should be like.....
http://domain.app/admin/blog/post/2/admin
AND
return view ($end.'.blog.single', ['post' => $post]);//remove , and add .
Upvotes: 1