there is a url - / public / articles / 20 / edit where 20 is a variable in the blade I do a check if the url so-and-then displays one if something else. How to get this variable?

    3 answers 3

    If you have correctly configured the route (with a variable), then a variable is passed to the controller that executes this route. It needs to be passed to the blade.

    Here is an example of a basic controller class. The installation is:

    namespace App \ Http \ Controllers;

    use App \ User; use App \ Http \ Controllers \ Controller;

    class UserController extends Controller {/ ** * Show the profile for the given user. * * @param int $ id * @return Response * / public function showProfile ($ id) {return view ('user.profile', ['user' => User :: findOrFail ($ id)]); }}

    We can route to the controller action like so:

    Route :: get ('user / {id}', 'UserController @ showProfile');

    https://laravel.com/docs/5.1/controllers#basic-controllers

      Try this

      routes.php

      Route::get('/public/articles/{article}/edit', ['as' => 'public.article', 'uses' => 'PublicController@article']); 

      App \ Http \ Controllers \ PublicController.php

       public function article($article) { $article = Post::latest('post_id')->where('posts.post_id', '=', $article)->get(); if(empty($article)){ return view('errors.404'); // если то другое } return view('public.article', ['article' => $article]); // url такой-то то вывожу одно } 

        this is how I solved my problem with View :: make

         public function edit($id){ $article=Article::find($id); $categories=Category::all(); View::make('admin.main', $id); return view('admin.articles.edit' ['article'=>$article,'categories'=>$categories]); }