Use of undefined constant category Laravel error - php

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

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>

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>
Delete

Related

Laravel orderBy working while doing dd but not in table while fetching

Into my laravel application while I am fetching data by eager loading order by showing me the correct format of data in dd i.e. the data in DESC format, but while i am compacting data and trying to show it in blade it shows the data in ASC format...
My controller
public function index(Request $request)
{
$data = Rate::with('hospital')->orderBy('id','DESC')->get();
// dd($data );
return view('admin.rates.index',compact('data'));
}
My blade file
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
{{-- <th>No</th> --}}
<th>Hospital</th>
<th>Contract Date</th>
<th class="text-center">Contract Length (weeks)</th>
<th>Weekly</th>
<th>Hourly</th>
<th>Others</th>
{{-- <th>Status</th> --}}
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $i=0; ?>
#foreach ($data as $key => $rate)
<tr>
{{-- <td>{{++$i}}</td> --}}
<td>
{{ ucwords($rate->hospital->short_name) }}
</td>
<td>
{{date('m/d/Y',strtotime($rate->contract_date))}}
</td>
<td class="text-center">
{{ $rate->contract_duration}}
</td>
<td class="text-right">
{{ ($rate->weekly_rate != '') ? $rate->weekly_rate : '' }}
</td>
<td class="text-right">
{{ ($rate->hourly_rate != '') ? $rate->hourly_rate : '' }}
</td>
<td class="text-right">
{{ ($rate->others_rate != '') ? $rate->others_rate : '' }}
</td>
{{-- <td>
</td> --}}
<td>
#if ($rate->status=='inactive')
<i class="fas fa-times"></i>
#else
<i class="fas fa-check"></i>
#endif
<a class="btn btn-sm btn-info" href="{{ route('rate.edit',$rate->id) }}"><i class="fas fa-edit"></i></a>
<a class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete')" href="{{ route('rate.destroy',$rate->id) }}"><i class="fas fa-trash"></i></a>
</td>
</tr>
#endforeach
</tbody>
</table>
There is nothing much more in it but why the data are not showing in DESC format is my question??? I am also pasting my dd image below where you can see the first data has the id 8 and the second one id 7 which is totally correct but while fetching id 7 comes first why??
When you are using datatable it tries to filter or sort the data in nearest alphabetical order if serial number is not in use I saw that you have closed tag for serial no try to open it and check the result. I am quite sure it is due to that... Just try to use "ordering": false into your datatable function..

laravel 8 crude operation not showing

i have laravel connected
to database mysql
when i do insert/update i find it on the mysql table
but the page show data does not reflect the change
my page is products.
the web route:
<?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\ProductController;
Route::get('/', function () {
return view('welcome'); });
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::resource('products', ProductController::class);
the show index.blade.php page :
#extends('products.layout')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Laravel 8 CRUD Example from scratch - ItSolutionStuff.com</h2>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('products.create') }}"> Create New Product</a>
</div>
</div>
</div>
#if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
#endif
<table class="table table-bordered">
<tr>
<th>No</th>
<th>Name</th>
<th>Details</th>
<th width="280px">Action</th>
</tr>
#foreach ($products as $product)
<tr>
<td>hi</td>
<td>{{ $product->name }}</td>
<td>{{ $product->detail }}</td>
<td>
<form action="{{ route('products.destroy',$product->id) }}" method="POST">
<a class="btn btn-info" href="{{ route('products.show',$product->id) }}">Show</a>
<a class="btn btn-primary" href="{{ route('products.edit',$product->id) }}">Edit</a>
#csrf
#method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
#endforeach
</table>
#endsection
does any one can give me the reason why change not reflected
enter image description here
In your controller, after updating product, try to do:
return redirect()->back();

I want to disable the delete post button inside in post foreach blade.. Laravel

I want to disable the delete post button inside in post foreach blade laravel . where post has created_at in database , i want the " delete post button" get disable after 15 days
i tried with some javascript tutorials but i couldn't achieve that thing
Can anyone please help me.it would be much appreciated if you could help me
thanks in adavance
<table id="" class="table ">
<thead>
<tr class="data-item master">
<th>Name</th>
<th>post</th>
<th>about</th>
<th>image</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
#foreach($data as $d)
<tr>
<td>{{$d->name}}</td>
<td>{{$d->postbody}}</td>
<td>{{$d->about}}</td>
<td>{{url($d->image)}}</td>;
<td><a href="{{ URL::to('edit/product/'.$d->id) }} "
class="btn btn-sm btn-info" title="edit">
<i class="fa fa-edit">edit post</i></a>
</td>
<td><a href="{{ URL::to('delete/product/'.$d->id) }} "
class="btn btn-sm btn-info" title="delete">
<i class="fa fa-trash"></i>delete post</a>
</td>
</tr>
#endforeach
</tbody>
</table>
You can not disable an anchor tag but you can change the URL to # as dummy url
#if(\Carbon\Carbon::parse($d->created_at)->addDays(15) < \Carbon\Carbon::now())
<a href="#"
class="btn btn-sm btn-info" title="delete">
<i class="fa fa-trash"></i>delete post</a>
#else
<a href="{{ URL::to('delete/product/'.$d->id) }}"
class="btn btn-sm btn-info" title="delete">
<i class="fa fa-trash"></i>delete post</a>
#endif
It's simple use and conditional statement on the disable attribute.
Something like This
<button class="anyClass" {{ Carbon::addDays(15)->greaterThan($post->created_at) ? 'disable' : ' }}>Delete</button>
I think something like this will work

Trying to delete a row in a table which is not the first one with jquery

I have a question regarding jquery and modal in my laravel project (here it's a blade file). I have a table of several artist, each row reference an artist. There is also a column delete. For each row of artist, when I click on delete, the modal appears asking if i am sure to cancel etc... I am able to delete the first artist but if I select another one, it doesn't work. I think I have to take the id of the artist but I don't know how, someone can help ?
Thanks
<div class="col-md-8">
<table class="table table-bordered table-striped table-condensed css-serial">
<div class="btn pull-right col-md-4">
<a class="btn btn-primary" href="{{ route('create-artist') }}" role="button">Create a new Artist or Band</a>
</div>
<thead>
#if(!$artists->isEmpty())
<h1>ARTISTS & BANDS:</h1>
<tr>
<th>#</th>
<th>Artist</th>
<th>Music genre</th>
<th>Picture</th>
<th>Edition</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
#foreach ($artists as $artist)
<form>
<tr>
<td></td>
<td>{{ $artist->artist_name}}</td>
<td>{{ $musicgenres[$artist->music_genre]}} </td>
<td><img src="../images/uploads/pictures_band/{{$artist->picture}}" style="width:80px; height:80px; border-radius:50%;" ></td>
<td>Show</td>
<td><a class="btn btn-danger" id="delete_id">Remove</a></td>
</tr>
</form>
<div id="delete-confirm" class="modal" data-backdrop="static" data-keyboard="true">
<div class="vertical-alignment-helper">
<div class="modal-dialog vertical-align-center">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title text-center">Warning</h4>
</div>
<div class="modal-body">
<p class="text-center">Are you sure you want to delete this Artist ? It will delete Tour and concert belong to this artist !</p>
<form action="{{ route('delete-artists', ['id' => $artist->id] )}}">
<div class="text-center" >
<button type="submit" class=" btn btn-primary " > Okay</button>
<button type="button" class=" btn btn-primary " data-dismiss="modal" > Cancel</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endforeach
#else
<h3>'There is no artist or band yet !'</h3>
#endif
</tbody>
</table>
</div>
<script>
$('#delete_id').on('click',function(){
//var id = $(this).attr('id')
$('#delete-confirm').modal('show');
});
</script>
your remove button has an id, but the problem is that (most likely) you will have many buttons. id should have to one specific element. In my previous experience it broke some things (about modals), so i suggest you to change it into a class. after that in you have to modify your js to show the correct modal which is connected to your artist's button.

Laravel 5.1 View code result in syntax error, unexpected '')); ?>" ' (T_CONSTANT_ENCAPSED_STRING)

I have this warning:
Whoops, looks like something went wrong.
1/1
FatalErrorException in f042f5969df1fc17d22527840a4806ba line 59:
syntax error, unexpected '')); ?>"
' (T_CONSTANT_ENCAPSED_STRING)
in f042f5969df1fc17d22527840a4806ba line 59
I've tried to find the problem but still not be able find it. This is my code of index.blade.php
<div class="container-fluid">
`#extends('admin.layout')`
`#section('content')`
<div class="row page-title-row">
<div class="col-md-6">
<h3>Posts <small>ยป Listing</small></h3>
</div>
<div class="col-md-6 text-right">
<a href="{{ URL('/admin/post/create')}}" class="btn btn-success btn-md">
<i class="fa fa-plus-circle"></i> New Post
</a>
</div>
</div>
<div class="row">
<div class="col-sm-12">
`#include('admin.partials.errors')`
`#include('admin.partials.success')`
<table id="posts-table" class="table table-striped table-bordered">
<thead>
<tr>
<th>Published</th>
<th>Title</th>
<th>Subtitle</th>
<th data-sortable="false">Actions</th>
</tr>
</thead>
<tbody>
#foreach ($posts as $post)
<tr>
<td data-order="{{ $post->published_at->timestamp }}">
{!! $post->published_at->format('j-M-y g:ia') !!}
</td>
<td>{!! $post->title !!}</td>
<td>{!! $post->subtitle !!}</td>
<td>
<a href="{{ URL('/admin/post/'.$post->id.'/edit')}}"
class="btn btn-xs btn-info">
<i class="fa fa-edit"></i> Edit
</a>
<a href="{{ URL('/blog/'.$post->slug')}}"
class="btn btn-xs btn-warning">
<i class="fa fa-eye"></i> View
</a>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
`#stop`
-------------------------------------------------------------line 59
`#section('scripts')`
<script>
$(function() {
$("#posts-table").DataTable({
order: [[0, "desc"]]
});
});
</script>
`#stop`
This is your error here
"{{ URL('/blog/'.$post->slug')}}"
The single quote after slug.
Try removing the quote at the end of this {{ URL('/blog/'.$post->slug')}} so it will look like {{ URL('/blog/'.$post->slug)}}

Categories