Route [$products.edit] not defined - model-view-controller

#foreach($products as $product)
<tr>
<td>{{ $product->id }}</td>
<td>{{ $product->name }}</td>
<td>{{ $product->job_category }}</td>
<td>{{ $product->purpose }}</td>
<td>{{ $product->region }}</td>
<td>{{ $product->email }}</td>
<td>{{ $product->contact }}</td>
<td>Edit</td>
<td>
<form action="{{ route('$products.destroy', $product->id) }}" method="post">
#csrf
#method('DELETE')
<button class="btn btn-danger" type="submit">DELETE</button>
</form>
</td>
</tr>
#endforeach
This is my ProductController
$product = Product::findOrFail($id);
return view('products.edit', compact('product'));
And this is my route
Route::resource('products', 'ProductController');

Just remove $ from route name
here
href="{{ route('$products.edit', $product->id) }}"
//and here :
action="{{ route('$products.destroy', $product->id) }}"
should be
href="{{ route('products.edit', $product->id) }}"
action="{{ route('products.destroy', $product->id) }}"

Related

Dynamic V-model name in a v-for loop Vue

I am developing an application and I am using Vue and laravel , inside a v-for loop I need error.id in the loop to be bound to the v-model name of the elements, this my code:
<tbody class="bodycol">
<tr v-for="error in errors.error" :key="error.id" >
<td>{{ error.client }}</td>
<td>{{ error.session }}</td>
<td>{{ error.info_session }}</td>
<td>{{ error.UPROC }}</td>
<td>{{ error.num_session }}</td>
<td>{{ error.num_exec }}</td>
<td>{{ error.date_debut }}</td>
<td>{{ error.heure_debut }}</td>
<td>{{ error.date_fin }}</td>
<td>{{ error.heure_fin }}</td>
<td>{{ error.status }}
<form #submit="addComment(error.id)" >
<div class="form-group">
<input v-model="form.comment[error.id]" type="text" name="comment"
class="form-control area" :class="{ 'is-invalid': form.errors.has('comment') }"
required>
<has-error :form="form" field="comment"></has-error>
</div>
</form>
</td>
</tr>
data(){
return{
comment:[],
}
}
the problem is the output of the errors.status is:
[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"the comment is here"]
Change your data to this. You are referencing form.comment not comment
export default {
data() {
return {
form: {
comment: []
}
}
}
}

Laravel. image cannot be display

enter image description herePhoto is in public/image folder
and the image cannot be fetched properly
#foreach($lostitem as $item)
<tr>
<td>{{ $item->LostItemID }}</td>
<td>{{ $item->date }}</td>
<td>{{ $item->TimeFound }}</td>
<td>{{ $item->AreaWhereFound }}</td>
<td><img src="{{ asset('public/images/'.$item->image) }}" alr="image"></td>
<td>{{ $item->Remark }}</td>
<td>{{ $item->UserLevelID }}</td>
<td>{{ $item->DateClaimed }}</td>
<td>{{ $item->TimeClaimed }}</td>
<td>{{ $item->created_at->format('Y-m-d g:i a') }}</td>
<td>{{ $item->updated_at }}</td>
<td>
<a href="{{route('LostItem_edit', $item->code) }}" class="btn btn-sm btn-info">
<i class="fa fa-edit"></i>
</a>
<form method="POST"
action="{{ route('LostItem_delete', $item->code) }}">
{{ csrf_field() }}
{{ method_field('delete') }}
<button class="btn btn-sm btn-danger" onclick="return confirm('Are you Sure?');">
<i class="fa fa-trash"></i>
</button>
</form>
</td>
</tr>
#endforeach
this is the code is used in the view to fetch the photo
You have already used asset() so you dont have to write public inside path
Try with this . Hope this helps
<td><img src="{{ asset('images/'.$item->image) }}" alr="image"></td>
Although it cant be the definite solution because it really depends upon how you have saved your image and its better if u have posted the controller logic too .
Let me know !
Change your this code from this
<img src="{{ asset('public/images/'.$item->image) }}
to this :
<img src="{{ asset('/images/'.$item->image) }}
Here You just Ignore the public because you use asset..In the simplest form, assets means JavaScript, CSS, and images which lie directly under the public directory and are publicly accessible using a URL.
Laravel provides a helper function, asset(), which generates a URL for your assets.
So just add write this
<td><img src="{{ asset('/images/'.$item->image) }}" alr="image"></td>
But My suggestion to you that when you save the file on database you save it with the all path after public path
how about use url()
<img src="{{url('images/'.$item->image)}}" alt="Image"/>

How to pass id in href to show the details on nextpage using laravel

actually i am getting the all position details, but I need to show details of particular position while clicking a button in list of positions in a datatable.
demo1.blade.php
#foreach ($jobposts as $jobpost)
<tr>
<td>{{ $jobpost->job_code }}</td>
<td>{{ $jobpost->position }}</td>
<td>{{ $jobpost->department }}</td>
<td>{{ $jobpost->location }}</td>
<td>{{ $jobpost->employement_type }}</td>
<td>{{ $jobpost->created_at }}</td>
<td><a href="/demo2"><button class="btn btn-default btn-
apply">Apply</button></a></td>
</tr>
#endforeach
demo2.blade.php
#foreach ($jobposts as $jobpost)
<h4 class="heading color">Basic Eligibility Criteria: {{ $jobpost->position }}</h4>
<hr>
<p><strong>Job Code:</strong> {{ $jobpost->job_code }} </p>
<p><strong>Job Discription:</strong> {{ $jobpost->job_discription }} </p>
<p><strong>Skills Required:</strong> {{ $jobpost->skills_required }} </p>
<p><strong>Eligibility:</strong> {{ $jobpost->eligibility }} </p>
<p><strong>Package:</strong> {{ $jobpost->package }} </p>
<p><strong>Department:</strong> {{ $jobpost->department }} </p>
<p><strong>Location:</strong> {{ $jobpost->location }} </p>
<p><strong>Employement Type:</strong> {{ $jobpost->employement_type }} </p>
<p><strong>Note:</strong> {{ $jobpost->detail }} </p>
#endforeach
DemoController.php
public function index()
{
$jobposts = DB::table('jobposts')->select('job_code','position','department','location','employement_type','created_at')->get();
return view('home.demo1')->with('jobposts', $jobposts);
}
public function jobcode()
{
$jobposts = DB::table('jobposts')->get();
return view('home.demo2')->with('jobposts', $jobposts);
}
web.php
Route::get('/demo1', 'CareerController#index');
Route::get('/demo2', 'CareerController#jobcode');
<td></td>
in web.php
Route::get('/demo/{id}', 'DemoController#index');
in DemoController.php
public function index($id)
{
// Your code
}

Delete function in view | Laravel

I have this function to delete only a row from a table in my database.
public function delete($id)
{
DB::table('user')->where('userID', '=', $id)->delete();
return redirect('userAdmin');
}
And I have a button which gets created for every row.
#foreach ($scores as $score)
<tr>
<td>{{ $score->id }}</td>
<td>{{ $score->serialnumber }}</td>
<td>{{ $score->name }}</td>
<td>{{ $score->created_at }}</td>
<td></td>
<td>
<button class="btn btn-danger" type="submit">Delete this Row</button>
{{ csrf_field() }}
</td>
</tr>
How do I get a delete functionality behind it?
In your view:
<form action="{{ route('yourmodel.delete', $score->id) }}" method="post">
{{ csrf_field() }}
<input name="_method" type="hidden" value="DELETE">
<button class="btn btn-danger" type="submit">Delete</button>
</form>
Add a route with a name you like, and a parameter for the id. Let that route call the method in your example and you should be good.
There isn't really such a thing as a DELETE function in HTML forms, so you have to spoof it. Take a look at the docs.
In your view:
<form action="{{ route('yourmodel.delete', $score->id) }}" method="post">
{{ csrf_field() }}
#foreach ($scores as $score)
<tr>
<td>{{ $score->id }}</td>
<td>{{ $score->serialnumber }}</td>
<td>{{ $score->name }}</td>
<td>{{ $score->created_at }}</td>
<td></td>
<td>
<button class="btn btn-danger" type="submit">Delete this Row</button>
</td>
#endforeach
</form>
In your routes:
Route::post('Test/{id}', 'TestController#delete')->name('yourmodel.delete');

Laravel Resource controller not getting delete route on amchor click

In laravel, I have resource controller :
Route::resource('/student','StudentController');
here is my view listing code :
<tr>
<td>{{ $key + $models->firstItem() }}</td>
<td>{{ $model->name }}</td>
<td>{{ $model->email }}</td>
<td>{{ $model->roll_no }}</td>
<td>{{ $model->StudentDetail->phone }}</td>
<td>{{ $model->StudentDetail->course }}</td>
<td>{{ $model->StudentDetail->city }}</td>
<td>{{ $model->StudentDetail->state->state_name }}</td>
<td>
Edit |
Link
</td>
</tr>
conytroller function i have :
public function destroy($id)
{
echo "ok";
}
My problem is that when I click on anchor button(delete ) it not
found the resource route for the delete what I am doing wrong here can
anyone please help me elated this.
when I click on the delete anchor it calls the show function of resource but I want the destroy function to call on click.
destroy function use DELETE method
in your blade view
#foreach($students as $model)
<tr>
<td>{{ $key + $models->firstItem() }}</td>
<td>{{ $model->name }}</td>
<td>{{ $model->email }}</td>
<td>{{ $model->roll_no }}</td>
<td>{{ $model->StudentDetail->phone }}</td>
<td>{{ $model->StudentDetail->course }}</td>
<td>{{ $model->StudentDetail->city }}</td>
<td>{{ $model->StudentDetail->state->state_name }}</td>
<td>
Edit |
DELETE
<form id="delete_form" style="display:none" action="{{ route('student.destroy',$model->id)}}" method="POST" >
{{ csrf_field() }}
<input type="hidden" name="_method" value="delete" />
</form>
</td>
</tr>
#endforeach

Resources