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"/>
Related
#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) }}"
what's wrong with my routes? it can't redirect to my edit-info form inside InfosController
web.php
route::get('/info-admin/{$info}/edit','InfosController#edit');
info-admin.blade.php
#foreach ( $info as $infos )
<tr>
<th scope="row" class="align-middle">{{ $loop->iteration }}</th>
<td class="align-middle">{{ $infos->judul }}</td>
<td class="align-middle">{{ $infos->konten }}</td>
<td class="align-middle">{{ $infos->image }}</td>
<td class="align-middle">{{ $infos->created_at }}</td>
<td class="align-middle">{{ $infos->Updated_at }}</td>
<td class="align-middle form">
<button type="submit" class="btn btn-info mb-3">Edit</button>
<form method="POST" action="{{ route('infos.destroy', [$infos->id]) }}">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit" class="btn btn-danger">Hapus</button>
</form>
</td>
</tr>
#endforeach
InfosController#edit
public function edit($id)
{
return view('admin.edit-info');
}
what did I do wrong, why laravel can't find my routes?
You route is defined wrong.
route::get('/info-admin/{$info}/edit','InfosController#edit');
Should be without $ and name the route for easier linking.
route::get('/info-admin/{info}/edit','InfosController#edit')->name('infos.edit');
Instead of hard coding it, use route as you do with destroy on the edit link too.
<a href="{{ route('infos.edit', [$infos->id]) }}">
To check if you routes are defined correctly, try running in the project.
php artisan route:list
There are multiple ways by which you can accomplish this:
Edit
Edit
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
}
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');
I am working on a laravel project.My table shows some value and if i click eye icon to view then more details of that table shows in the modal.But i don't know how to pass the image source in anchor tag data value.
#foreach ($employees as $employee)
<tr class="post{{$employee->id}}">
<td>{{ $no++ }}</td>
<td>{{ $employee->name}}</td>
<td>{{ $employee->bank->name}}</td>
<td>{{ $employee->bankbranch->location}}</td>
<td><img alt="Smiley face" height="50" width="70" src="{{url('images',$employee->image)}}"/></td>
<td>{{ $employee->created_at}}</td>
<td>
<a href="#" class="show-modal btn btn-info btn-sm" data-id="{{$employee->id}}" data-bank_id="{{$employee->bank->name}}" data-bankbranch_id="{{$employee->bankbranch->location}}" data-salary="{{$employee->salary}}" data-qincentive="{{$employee->qincentive}}" data-fbonus="{{$employee->fbonus}}" data-hrent="{{$employee->hrent}}" data-ename="{{$employee->ename}}" data-ephone="{{$employee->ephone}}" data-relationship="{{$employee->relationship}}" data-gender="{{$employee->gender}}" data-religion="{{$employee->religion}}" data-bgroup="{{$employee->bgroup}}" data-mstatus="{{$employee->mstatus}}" data-transportallowance="{{$employee->transportallowance}}" data-eaddress="{{$employee->eaddress}}">
<i class="fa fa-eye"></i>
</a>
</td>
</tr>
#endforeach
You just need to change your src to src=“{{$employee->image}}” providing the image url is stored in that variable. If not then you’ll need to do concatenation like src=“{{‘/images/’ . {{$employee->image}}”