how to make readable the url of an image that comes from an api that I created? - laravel

I created an api it's been 2 weeks. the api works well but I can't retrieve the images from this api during my HTTP requests.
My Controller Api/admin/AgencyController
`
public function store(AgencyRequest $request)
{
if ($request->hasFile('logo')) {
$path = $request->file('logo')->store('logo','public');
}
$agency=Agency::create([
'name'=>$request->name,
'headquarters'=>$request->headquarters,
'email'=>$request->email,
'logo'=>$path,
'phone_number'=>$request->phone_number,
'state'=>$request->state,
'password'=>bcrypt($request->password),
]);
return new AgencyResource($agency);
}
`
My index file
`
#foreach ($datas as $agencies)
#forelse ($agencies as $agency)
<tr>
<td><img src="{{ url('https://kipart.stillforce.tech/storage/'.$agency->logo) }}" width="48" alt="Product img"></td>
<td><h5>{{ $agency->logo }}</h5></td>
<td>
<i class="zmdi zmdi-edit"></i>
<form method="POST" action="{{ route('admin.agencies.destroy', $agency->id) }}" onsubmit="return confirm('Are you sure?')">
#csrf
#method('delete')
<button type="submit" class="btn btn-default waves-effect waves-float btn-sm waves-red" ><i class="zmdi zmdi-delete" aria-hidden="true" title="Suprimer"></i></button>
</form>
</td>
</tr>
`
#foreach ($datas as $agencies)
#forelse ($agencies as $agency)
<tr>
<td><img src="{{ url('https://kipart.stillforce.tech/storage/'.$agency->logo) }}" width="48" alt="Product img"></td>
<td><h5>{{ $agency->logo }}</h5></td>
<td>
<i class="zmdi zmdi-edit"></i>
<form method="POST" action="{{ route('admin.agencies.destroy', $agency->id) }}" onsubmit="return confirm('Are you sure?')">
#csrf
#method('delete')
<button type="submit" class="btn btn-default waves-effect waves-float btn-sm waves-red" ><i class="zmdi zmdi-delete" aria-hidden="true" title="Suprimer"></i></button>
</form>
</td>
</tr>
When I do a test registration of an agency. all the data is registered but when I retrieve the image to a flutter client or a laravel client the image does not appear but all the data is called

Related

How to get id of slider for get slider_group?

I have two tables sliders and slider_group.
In my controller in create function in laravel, I want the get the id that shows in browser show when I browse it shows like this.
http://localhost:8000/admin/sliders/create/21
blade
<a href="{{ route('admin::sliders.create', ['groupId', $sliderGroup->id]) }}" class="mr-1">
Now how to get the id of slider_group table to group_id of requisitions.
<tbody>
#foreach($sliderGroups as $sliderGroup)
<tr>
<td class="text-truncate">
<i class="la la-dot-circle-o success font-medium-1 mr-1"></i>
{{ $sliderGroup->id }}
</td>
<td class="text-wrap">
{{ $sliderGroup->title }}
</td>
<td class="text-wrap">
{{ getShamsiDate($sliderGroup->created_at) }}
</td>
<td>
<div class="row">
<a href="{{ route('admin::sliders.create', ['groupId', $sliderGroup->id]) }}" class="mr-1">
<i class="la la-plus text-grey text-shadow-custom font-medium-4 font-weight-normal"></i>
</a>
<a href="{{ route('admin::slider-groups.edit', $sliderGroup->id) }}" class="mr-1">
<i class="ft-edit text-grey text-shadow-custom font-medium-4 font-weight-normal"></i>
</a>
<form action="{{ route('admin::slider-groups.destroy', $sliderGroup) }}" method="post" #submit.prevent="confirmDelete">
#method('delete')
#csrf
<button type="submit" class="btn btn-default p-0">
<i class="ft-trash-2 text-grey font-medium-5 font-weight-normal"></i>
</button>
</form>
</div>
</td>
</tr>
#endforeach
</tbody>
I get this in address bar like this
http://localhost:8000/admin/sliders/create?groupId&3
It has an error.
404 | Not Found
Controller
public function index(Request $request)
{
if ($request->search) {
$sliderGroups = SliderGroup::search($request->search)->paginate(30);
} else {
$sliderGroups = SliderGroup::paginate(30);
}
if ($sliderGroups->count() == 0 && $request->search ) {
msg()->warning('it is not found.');
}
return view('slider::admin.groups.index', compact('sliderGroups'));
}
web.php
Route::group([
'prefix' => 'admin',
'as' => 'admin::',
], function() {
Route::resource('sliders', 'Admin\SliderController');
Route::resource('slider-groups', 'Admin\SliderGroupController');
});

can't refresh a page after updateing a form in laravel

hello i need to do an update inside a model using Laravel, the problem is when i click on the update button (his name in the code is Modifier) the page is not refreshing.
i have tried to work with an a tag in place of button .and with the a tag the page refresh but my data is not updating.
can someone tell me where is the problem in the code
the index view code :
<table class="table table-bordered table-left">
<thead>
<tr>
<th>#</th>
<th>Nom</th>
<th>Email</th>
<th>Rôle</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#foreach ($users as $key=>$user)
<tr>
<td>{{ $key+1 }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>
#if ($user->is_admin==1)Administrateur
#else Caissier
#endif
</td>
<td>
<div class="btn-group">
<a class="btn btn-success" href="" data-toggle="modal" data-target="#edituser{{ $user->id }}">
<i class="fas fa-edit"></i>
</a>
<a href="" class="btn btn-danger">
<i class="fas fa-trash"></i>
</a>
</div>
</td>
</tr>
{{-- edit model --}}
<div class="modal right fade" id="edituser{{ $user->id }}" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="staticBackdropLabel">Modifier l'utilisateur</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{ route('users.update', $user->id) }}" method="post">
#csrf
#method('put')
<div class="form-group">
<label for="name">Nom</label>
<input type="text" value="{{ $user->name }}" name="name" class="form-control">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" value="{{ $user->email }}" name="email" class="form-control">
</div>
<div class="form-group">
<label for="name">Mot de passe</label>
<input type="password" readonly name="password" value="{{ $user->password }}" class="form-control">
</div>
{{-- <div class="form-group">
<label for="name">Confirmer le mot de passe</label>
<input type="password" name="confirm_password" class="form-control">
</div> --}}
<div class="form-group">
<label for="name">Rôle</label>
<select name="is_admin" id="" class="form-control">
<option value="1" #if ($user->is_admin==1)
selected
#endif>Administrateur</option>
<option value="2" #if ($user->is_admin==2)
selected
#endif>Caissier</option>
</select>
</div>
<div >
<button class="btn btn-success btn-block">Modifier</button>
</div>
</form>
</div>
</div>
</div>
</div>
#endforeach
</tbody>
</table>
the controller code :
public function update(Request $request, $id)
{
$users = User::find($id);
if (!$users) {
return back()->with('Error','user created');
}
$users->update($request->all());
return back()->with('Success','user created');
}
Your button
<button class="btn btn-success btn-block">Modifier</button>,
should be
<button class="btn btn-success btn-block" type="submit">Modifier</button> in order to submit the form to your controller.

Laravel - How to Customize Ellipsis with a button

I have a web application project using Laravel-5.8. In the project, I applied HTML text editor.
Controller
public function create()
{
return view('organization.announcements.create');
}
public function store(StoreAnnouncementRequest $request)
{
try {
$announcement = new OrgAnnouncement();
$announcement->title = $request->title;
$announcement->description = $request->description;
$announcement->save();
Session::flash('success', 'Announcement is created successfully');
return redirect()->route('organization.announcements.index');
} catch (Exception $exception) {
Session::flash('danger', 'Announcement creation failed!');
return redirect()->route('organization.announcements.index');
}
}
View
<table class=" table table-bordered table-striped table-hover datatable">
<thead>
<tr>
<th width="10">
#
</th>
<th>
Announcement Title
</th>
<th>
Description
</th>
<th>
</th>
</tr>
</thead>
<tbody>
#foreach($announcements as $key => $announcement)
<td>
{{$key+1}}
</td>
<td>
{{$announcement->title ?? '' }}
</td>
<td>
{{str_limit($announcement->description, $limit = 20, $end = ' ...')}}
</td>
<td>
#can('announcement_show')
<a class="btn btn-xs btn-primary" href="{{ route('organization.announcements.show', $announcement->id) }}">
{{ trans('global.view') }}
</a>
#endcan
#can('announcement_edit')
<a class="btn btn-xs btn-info" href="{{ route('organization.announcements.edit', ['id'=>$announcement->id]) }}">
{{ trans('global.edit') }}
</a>
#endcan
#can('announcement_delete')
<a class="btn btn-xs btn-danger" data-toggle="modal" data-target="#confirm-delete{{ $announcement->id }}" data-original-title="Close">
<span style="color:white;">{{ trans('global.delete') }}</span>
</a>
#endcan
<div class="modal fade" id="confirm-delete{{ $announcement->id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Delete Announcement</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{route('organization.announcements.destroy',$announcement->id)}}" method="post">
{{ csrf_field() }}
<p>Are you sure you want to delete this Announcement?</p>
<div class="modal-header">
<h4>{{ $announcement->title }}</h4>
</div>
</form>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">Delete</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
</td>
</tr>
#endforeach
</tbody>
</table>
The field description is the text editor. On the view blade, I truncated the field description to 20 characters and ... will be displayed as shown in my field.
However, what I want to achieve is that I want to replace the ... with a button that will have view more. Then it is clicked, it will show the full content in a modal form of redirect to another page.
How do I achieve this?
Thank you
You may use
<td>
{{str_limit($announcement->description, $limit = 20, $end = ' ...')}}
#if(strlen($announcement->description) > 20)
Show more
#endif
</td>

#method('DELETE') and version 5.4.13

In my form index.blade, I see that my method delete() has a problem to display???
In my index.blade I have this:
#foreach($students as $student)
<tr>
<td> {{$student->name}}</td>
<td> {{$student->firstname}}</td>
<td>
<form method="POST" action="{{ route('students.destroy', $student) }} ">
<a class="btn btn-sm btn-warning" href="{{route('students.edit',$student->id)}}">Editer</a>
{{csrf_field()}}
#method('DELETE')
<button type="submit" class="btn btn-sm btn-danger">Effacer</button>
</form>
</td>
</tr>
#endforeach
In my Controller I have this:
public function destroy($id)
{
$students = Student::find($id);
$students->delete();
return redirect()->route('students.index')
->with('success', 'Effacé !');
}
For information, I have the version '5.4.13'.
Thank you
In laravel 5.4 you need to use
{{ method_field('delete') }}
From 5.6 #method('delete') is introduced.

Getting error while clicking on edit function button in laravel

I need to edit by data from database via my admin panel. So i created table with clickable button for edit function.
Now when I click on edit button, I am seeing ID number at bottom but getting sorry page couldn't found error ! I have double checked all controller, route and everything. It seems all good, but I don't know what's the error!
Route Code:
Route::get('/admin/baseFare',[
'uses' => 'ExtraBaseFareController#basefare',
'as' => 'base.fare'
]);
Route::get('/admin/baseFare/edit/{$id}',[
'uses' => 'ExtraBaseFareController#editBaseFare',
'as' => 'editbase.fare'
]);
Route::post('/admin/baseFare/update/{id}', [
'uses' => 'ExtraBaseFareController#baseFareUpdate',
'as' => 'base.fareupdate'
]);`
Controller Code:
public function basefare()
{
$base = BaseFare::all();
return view('Admin.BaseFare.index')->With('base', $base);
}
public function editBaseFare($id)
{
$base = BaseFare::find($id);
return view('Admin.BaseFare.editBaseFare')->with('base', $base);
}
public function baseFareUpdate(Request $request, $id)
{
$base = BaseFare::find($id);
$base->fareinpercentage = $request->fareinpercentage;
$base->fareinrupees = $request->fareinrupees;
$base->save();
Session::flash('success','Base fare successfully updated');
return redirect()->route('base.fare');
}
Index Page code:
<table class="table display nowrap table-striped table-bordered bootstrap-3 scroll-horizontal">
<thead>
<tr>
<th>S.No</th>
<th>Fare in Percentage (%)</th>
<th>Fare in Rupees (Rs)</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#php $number = 1; #endphp
#foreach($base as $base)
<tr>
<td>
{{ $number.'.' }}
#php $number++; #endphp
</td>
<td>{{ $base->fareinpercentage }}</td>
<td>{{ $base->fareinrupees }}</td>
<td>
<a href="{{ route('editbase.fare',['id' => $base->basefareid ]) }}" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill" title="Edit ">
<i class="la la-edit"></i>
</a>
</td>
</tr>
#endforeach
</tbody>
</table>`
Edit Page Code:
<form class="form" method="post" action="{{ route('base.fareupdate',['id' => $base->basefareid ]) }}">
<div class="form-body">
<h4 class="form-section"><i class="la la-eye"></i>Base Fare Controller</h4>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="userinput2">Fare in Percentage (%)</label>
<input type="text" id="fareinpercentage" value="{{ $base->fareinpercentage }}" class="form-control border-primary" name="fareinpercentage">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="userinput3">Fare in Rupee (Rs)</label>
<input type="text" id="fareinrupees" value="{{ $base->fareinrupees }}" class="form-control border-primary" name="fareinrupees">
</div>
</div>
</div>
</div>
<div class="form-actions right">
<button type="button" class="btn btn-warning mr-1">
<i class="ft-x"></i> Cancel
</button>
<button type="submit" name="submit" class="btn btn-primary">
<i class="la la-check-square-o"></i> Save
</button>
</div>
</form>`
These are the codes, the kindly help me to find our the error, The main function is to edit the field from database!
If I understand the question correctly you can't go to the edit page.
Run 'php artisan route:list' and compare the routes.
And I can't figure out why you have dollar sign before the id in the route.

Resources