I have Laravel Blog and it's working very well, first the URL to display post was "http://localhost:8000/post/rassel-beatifull-mind" & and the route '/post/{slug}', ['as' => 'site.post.show', 'uses' => 'SiteController@showPost']
, And now i want to change URL to "http://localhost:8000/edu/rassel-beatifull-mind" where "edu" is the category of the post, but when i change route to '/{category}/{slug}', ['as' => 'site.post.show', 'uses' => 'SiteController@showPost']
i got an error exception in every post->property, ($post->id, $post->title...)
ErrorException Trying to get property of non-object
There is showPost function
public function showPost($slug, $category)
{
$posts = $this->postModel->getAllPosts();
$post = $this->postModel->getPostBySlug($slug);
$lastPosts = $this->postModel->getLastPost();
$categories = $this->categoryModel->getCategories();
$relatedPosts = Post::whereHas('categories', function ($q) use ($categories) {
$q->whereIn('categories.id', $categories);
})->where('id', '<>', $post->id)->get();
Carbon::setLocale('ar');
$now=Carbon::now();
$creat_date = Carbon::parse($post->created_at);
$last_update_date = Carbon::parse($post->updated_at);
$created = $creat_date->diffForHumans($now);
$updated = $last_update_date->diffForHumans($now);
return view('site.post', [
'post' => $post,
'categories' => $categories,
'lastPosts' => $lastPosts,
'created' => $created,
'updated' => $updated,
'relatedPosts' => $relatedPosts,
])->withPosts($posts)->withCategories($categories)->withLastPosts($lastPosts);
}
And url href
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mK1PDz
via IFTTT
Aucun commentaire:
Enregistrer un commentaire