Problem with route show function LARAVEL

0

After a lot of searching for google and not finding a solution to my problem, I decided to ask the wisdom of the internet:

These are my routes:

Route::get('/customers', 'CustomerController@index')
->name('customerIndex');
Route::get('/customers/create', 'CustomerController@create')
->name('customerCreate');
Route::post('/customers', 'CustomerController@store')
->name('customerStore');
Route::get('/customers/{customer}', 'CustomerController@show')
->name('customerShow');
Route::get('/customers/{customer}/edit', 'CustomerController@edit')
->name('customerEdit');
Route::put('/customers/{customer}', 'CustomerController@update')
->name('customerUpdate');
Route::delete('/customers/{customer}', 'CustomerController@destroy')
->name('customerDestroy');

Before I had:

Route::resource('customers', 'CustomerController');

The fact is that the route that goes to the show function does not do anything, any code that you put inside that function does not run.

The show function:

public function show($id)
{
    dd("hola");
    $customer = Customer::findOrFail($id);

    return view('customers.show', compact('customer'));

}

Someone would know how to tell me why the dd ('hello') is not even executed; An important detail, on sight if it arrives, but not because I put it in the return of the function, because if I remove it, I can still see the view.

Thanks in advance.

    
asked by Crtisian Navarro 16.10.2018 в 17:09
source

3 answers

0

Thanks for the answers, I already solved the error.

I had two controllers that used the same kind of controller and I was working with one and laravel with another.

    
answered by 22.10.2018 / 08:47
source
0

maybe you have another route that causes conflict.

If not, try cleaning the cache:

php artisan route:cache
php artisan route:clear
    
answered by 16.10.2018 в 19:19
0

One of the easiest ways to access the driver with the resources that laravel brings by default is with

Route::resource('customers','CustomerController');

This would be the code of the show method

 public function show($id)
    {
        $customer = Customer::findOrFail($id);

        return view('customers.show', compact('customer'));

Remember that you must have defined your models well since you are using eloquent and at least if something is wrong, you should have sent an error

and remember that to access the method show you should have defined before a button or link

@foeach($customer as $c) <a href="{{ route('customers.show', $c->id) }}"> @endforeach

    
answered by 21.10.2018 в 04:04