php - Laravel: How can I pass my join code to my route so that only users with this code can join a room?
Get the solution ↓↓↓I am trying to figure out how to pass a parameter in a route to my controller.
I have an entry join_code in my table which is associated to a paper. Every join code is unique and is generated when the user creates a paper.
$paper->join_code = $request->uuid;
Every paper can have different values, so I want only users with the join code allow to see the view make edits (theoretically every user with the join code can edit it but for now it should be enough for my use case).
I tried it the following way: First I defined the route in my api.php file:
Route::get('/paper/{join_code}', 'App\Http\Controllers\PaperController@main_paper')->name('show_paper');
Now in my PaperController.php
public function main_paper($join_code)
{
return view('paper');
}
And in my paper.blade.php file:
<div class="col-md-4">
<a href="{{route('show_paper' , [request()->get('join_code')])}}">
<div>
<div class="new">
Hello
</div>
</div>
</a>
</div>
So f.e. when a user selects a button join room he can enter the join code and gets redirected to the associated paper which is stored in the blade file. I think the corresponding url for a paper would be: api/conceptPaper/c5e24dd0-3a1c-11eb-9ad9-8fc9c3260704 . However it is not working and shows a 404.
UPDATE The url: http://127.0.0.1:8000/api/paper/c5e24dd0-3a1c-11eb-9ad9-8fc9c3260704 is throwing a 404. I expected that my blade file is returned.
Error when passing the value in an array as suggested here:
Missing required parameters for [Route: show_paper] [URI: api/paper/{join_code}]. (View: C:\Users\User\LaravelApp\resources\views\paper.blade.php) http://127.0.0.1:8000/api/paper/c5e24dd0-3a1c-11eb-9ad9-8fc9c3260704
Answer
Solution:
The second parameter for theroute()
function should be passed as an associative array.
{{ route('show_paper' , ['join_code' => request()->get('join_code')]) }}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: dompdf image not found or type unknown
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.