dimanche 26 novembre 2017

Laravel show Method with two redirect

I cant seem to figure this out. I looked around here and different laravel forums for a solution, but no luck. Hopefully someone can point me in the right direction.

I have a show method in my controller, if I delete a record and redirect back to show, the record will not be found since it has been deleted. So I want to check if eloquent returns a model instance, if it doesnt and returns a null, I would like to redirect to the index page.

Currently with this code, event if eloquent returns a model, my show page is tripping out and keeps reloading, like an endless loop. However, if I take the redirect from the if statement and put in a dd('if statement working') to see if it fails the if statement, it works find. So the issue is with the redirect statement.

Here is a snipped of my show method:

public function show($id)
{
    $vendor = $this->user->vendors()->find($id);

//if there are no results redirect to the index page.
    if(is_null($vendor)) {
        return redirect()->action('VendorsController@index');

    }

    session()->put('vendor_id', $vendor->id);
    return view('vendors.show', compact('vendor'));
}

Any help is appreciated!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zHSmVF
via IFTTT

Aucun commentaire:

Enregistrer un commentaire