dimanche 13 novembre 2016

Laravel5 doesn't return any latest article after the latest one gets deleted

I've just built a blog based on "Laravel 5 fundamentals", then I added the delete option for the articles myself. In my navbar there is an option called "Latest article", which consists of:

<ul class="nav navbar-nav navbar-right"> <li>{!! link_to_action('ArticlesController@show', 'Latest Article', [$latest->id]) !!}</li> </ul>

where the $latest comes from:

class AppServiceProvider extends ServiceProvider {

public function boot()
{
            view()->composer('partials.nav', function($view){

                $view->with('latest', \App\Article::latest()->first());

            });
}

But after I go to the latest article and delete it, then I click on the "Latest Article" again, it gives me the error "ModelNotFoundException in Builder.php line 125: No query results for model [App\Article]" (I think it doesn't find the same article again which has just been deleted). How could I manage to always return the latest article? Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire