PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 16, 2022

[FIXED] How to set the route in <a> tag with user id in Laravel 6?

 November 16, 2022     laravel, laravel-6, laravel-blade     No comments   

Issue

This is My index blade where I want to click on the user name and it will redirect me on the edit user blade

@extends('layouts.admin')

        @section('content')
          <h1><b>Users</b></h1>
          <table class="table table-hover">
              <thead>
              <tr>
                  <th scope="col">#</th>
                  <th scope="col">Profile</th>
                  <th scope="col">Name</th>
              </tr>
              </thead>
              <tbody>
              @if($users)
                  @foreach($users as $user)
              <tr>
                  <td>{{$user->id}}</td>
                  <td><img height="25" src="{{$user->photo ? $user->photo->file:'No photo exist'}}"></td>


                <!-- Problem is here -->
                  <td><a href="{{route('admin.users.edit', $user->id)}}" style="text-decoration: none"> 
                {{$user->name}}</a></td>


*it through an exception* 

**Route [admin.users.edit] not defined**       
              </tr>
                  @endforeach
                  @endif
              </tbody>
          </table>
        @endsection

If I use the url() method {{url('admin/users/edit',$user->id)}} like this it will redirect me as admin/users/edit/1 but my route is set as admin/users/1/edit. How can I open this route?


Solution

I will not suggest to use admin/users/1/edit even then if you want to use this then

Change

{{url('admin/users/edit',$user->id)}}

to

{{url('admin/users/'.$user->id.'/edit')}}

Reference:

Laravel ->URL Generation -> Generating Basic Url



Answered By - Sehdev
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing