abu abu
abu abu

Reputation: 7052

Using Resource controller in Laravel 5.6

I am Using Resource controller in Laravel 5.6. I am following this tutorial. I found here Resource controller uses the Route model binding, This means that you dont need to fetch the specified task by the id. Laravel will do it for you. $task variable which is passed into the show() method is passed to the view via compact method.

In my code I am using below code in Controller.

 /**
     * Display the specified resource.
     *
     * @param  \App\sura  $sura
     * @return \Illuminate\Http\Response
     */
    public function show(Sura $sura)
    {
        return $sura;
    }

Here I am getting the Whole Sura object not the id.

Why I am getting the whole object not the id ? Where is the issue ?

Upvotes: 0

Views: 72

Answers (1)

Davit Zeynalyan
Davit Zeynalyan

Reputation: 8618

https://laravel.com/docs/5.6/routing#route-model-binding When dependency inject model

public function show(Sura $sura)
{
    return $sura; // it is instance of Sura 
}

For get id use this

public function show($suraId)
{
    dd($suraId);// return integer number
}

Upvotes: 3

Related Questions