Liam S
Liam S

Reputation: 43

controller/create/id not allowing any data - Laravel

I'm designing a system where I need to create a comment that leaves a comment on a specific user's page.

Currently in my employercommentscontroller I have the create function

public function create($id)
{
    $user = User::where('employee_id', $id)->get();
    return view('comments.create', compact('user'));
}

Here is the route to this controller file

Route::resource('/reviews', 'EmployerCommentsController');

This is so that I can display information about the user that the comment is being left about. When I go to the url. When I visit /reviews/create/2, I get a notfoundhttpexception. What do I need to change to be able to pass just the ID to my create method?

Upvotes: 2

Views: 54

Answers (2)

Alexey Mezenin
Alexey Mezenin

Reputation: 163798

If you don't want to create additional routes and you want to use standard RESTful controller, you can just create link with GET parameter:

<a href="/reviews/create?id=2">Write a comment</a>

And then get this parameter in controller:

public function create()
{
    $id = request()->input('id');

Upvotes: 0

ch271828n
ch271828n

Reputation: 17597

You may use:

Route::get('/reviews/create/{id}', 'EmployerCommentsController@create');

For further information: https://laravel.com/docs/5.1/routing

Upvotes: 1

Related Questions