I want to open my webiste post with specific id, but when I go to this link which is first post page http://localhost:8000/tickets/create/1
its opening correct id (1 is id) but tells me that "404 not found".
There are my codes.
Controller
public function create()
{
$ticketsinfos = Tickets::with('companies')->get();
$tickets = Companies::with('tickets')->get();
$severities = Severities::with('severity')->get();
$ticketscounts = Tickets::count();
//return view('dashboard.index',['ticketscounts'=> $ticketscounts]);
$users = DB::table('tickets')->get();
return view('customer.index')->with(['tickets'=> $tickets])->with(['severities' => $severities])->with(['ticketsinfos' => $ticketsinfos])->with(['ticketscounts'=> $ticketscounts])->with(['users'=>$users]);
//dd($users->toArray());
}
Blade.php
<tr>
@foreach ($ticketsinfos as $ticketinfo)
<td>IR-173049</td>
<td>Tudro</td>
<td>{{ $ticketinfo->companies->name }}</td>
@foreach($users as $user)
<td><a href="tickets/create/{{ $user->id }}">{{ Str::limit($ticketinfo->ticket_title, 50, '...') }}</a></td>
@endforeach
<td><button class="btn btn-danger btn-sm" type="button">Action Needed<br></button><br></td>
<td>Tako Kiknadze</td>
<td>{{ $ticketinfo->created_at }}</td>
<td>{{ $ticketinfo->updated_at }}</td>
</tr>
@endforeach
</tr>
My route:
Route::resource('/tickets', TicketsController::class);
What can I do for do this?
2
Answers
there is a problem with your route
try updating your route to be like this:
and update your function like this:
So I think part of the issue is that the URL you are trying to go to is incorrect. You specified it was a Route::Resource. This is a shortcut in writing routes. What this does is create a list of routes as can be seen by a
artisan route:list
.The
Route::resource('/tickets', TicketsController::class);
line in web.php creates specific routes and points to the specific methods in that class.The specific methods are:
Personally, I like to use the artisan command
artisan make:model --all
orartisan make:model --resource
. I would suggest that you use aartisan make:controller --resource Bogus
and then see how it affects your routes. The default comments clearly spell out how each route is used and the parameters that it is expecting.@Bromerbeer I think was giving you the correct info. The "Create" route takes no parameters and does not accept any. From how you worded the question, it seems you would want
http://localhost:8000/tickets/show/1
Then it will accept an ‘id’ parameter (in this case a model) :
Where as the "create" method takes no parameters: