skip to Main Content

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


  1. there is a problem with your route

    try updating your route to be like this:

    Route::resource('tickets/create/{id}', TicketsController::class);
    

    and update your function like this:

    public function create($id)
    {
        $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')->where('id',$id)->get();
      
        return view('customer.index')->with(['tickets'=> $tickets])->with(['severities' => $severities])->with(['ticketsinfos' => $ticketsinfos])->with(['ticketscounts'=> $ticketscounts])->with(['users'=>$users]);
      
         //dd($users->toArray());
    }
    
    Login or Signup to reply.
  2. 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:

     - index : Display a listing of the resource.
     - create : Show the form for creating a new resource.
     - store : Store a newly created resource in storage.
     - show : Display the specified resource.
     - edit : Show the form for editing the specified resource.
     - update : Update the specified resource in storage.
     - destroy : Remove the specified resource from storage.
    

    Personally, I like to use the artisan command artisan make:model --all or artisan make:model --resource. I would suggest that you use a artisan 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) :

    /**
     * Display the specified resource.
     *
     * @param  AppModelsBogusModel  $bogus
     * @return IlluminateHttpResponse
     */
    public function show(BogusModel $bogus)
    {
        //
    }
    

    Where as the "create" method takes no parameters:

    /**
     * Show the form for creating a new resource.
     *
     * @return IlluminateHttpResponse
     */
    public function create()
    {
        //
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search