skip to Main Content

im working on laravel project and now its giving me this error:Use of undefined constant category – assumed ‘category’ (this will throw an Error in a future version of PHP)
and its pointing at lane 26
even though i declared the variable ‘category’ any ideas how to solve it ? thank you

@extends('layouts.app')

@section('content')
    <div class="card">
      <div class="card-body">
        <table class="table table-hover">
          <thead>
            <th>
              Category Name
            </th>

            <th>
              Editing
            </th>

            <th>
              Deleting
            </th>
          </thead>

          <tbody>
            @foreach($categories as $category)
              <tr>
                <td>{{$category->name}}</td>
                <td>
                  <a href="{{ route(category.edit, ['id=>$category->id']) }}" class="btn btn-light btn-xs">
                    Edit
                  </a>
                </td>

                <td>
                  <a href="{{route(category.delete, ['id => $category->id'])}}" class="btn btn-danger btn-xs">
                    Delete
                  </a>
                </td>


              </tr>

            @endforeach
          </tbody>

        </table>

      </div>


    </div>
@stop

2

Answers


  1. Use this route variable in commas, It’s worked for me.

     <a href="{{ route('category.edit', ['id=>$category->id']) }}" class="btn btn-light btn-xs">
                        Edit
                      </a>
    
    Login or Signup to reply.
  2. You need to change these below routes and i hope it will work for you!

    <a href="{{ route('category.edit', $category->id) }}" class="btn btn-light 
    btn-xs">Edit</a>
    
    
    <a href="{{'route(category.delete', $category->id)}}" class="btn btn-danger btn-xs"> Delete </a>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search