unisharp laravel-filemanager Thumbnail url - laravel

Hi I'm using unisharp laravel-filemanager for user to upload their products photos
when the image uploaded
this address will save in database
/photos/44/606074649c651.jpg
and I can use it by
{{asset('storage/'.$product->cover_img)}}
and Thumbnail saved in this address
/photos/44/thumbs/606074649c651.jpg
How can I get the address of thumbnail and how can I use it in blade?
This is the answer
#php($lastSlash = strrpos($product->cover_img,"/"))
src="{{asset('storage/'.substr_replace($product->cover_img, 'thumbs/', $lastSlash+1) .'' .substr($product->cover_img ,$lastSlash+1))}}"

One way to save it in the database is to add a hidden type input to the image's thumb, inside the stand-alon-button.js file.
// set or change the preview image src
items.forEach(function (item) {
target_preview.append(
$('<img>').css('height', '5rem').attr('src', item.thumb_url),
$('<input type="hidden" name="thumbnail">').attr('value', item.thumb_url)
);
});
Input:
<div class="input-group">
<span class="input-group-btn">
<a id="lfm" data-input="thumbnail" data-preview="holder" class="btn btn-primary">
<i class="fa fa-picture-o"></i> Choose
</a>
</span>
<input id="thumbnail" class="form-control" type="text" name="image">
</div>
<div id="holder" style="margin-top:15px;max-height:100px;"></div>

you can use a function like this:
function getThumbs($url=""){
$base = basename($url);
if (strpos($url, 'https://') !== false or strpos($url, 'http://') !== false) {
return str_replace($base, "thumbs/".$base, $url);
}else{
$preUrl = "storage/";
$beforeBase = str_replace($base, "",$url);
return $preUrl.$beforeBase.'thumbs/'.$base;
}
}
and in your blade use:
<img src="{{ getThumbs($product->cover_img) }}" .../>

Related

Cannot find parent element in DOM tree containing attribute: [wire:id]

I am laravel developer and developing a real time chat room using liveware , i am trying to open chat when i click to user but unfortunatly i am getting error https://flareapp.io/share/OmVDe437#F47 please help me how can resolved that ? thank u.
I am also getting error in console.
app\Http\Livewire\Messaging.php
public $selectedConservation;
public function mount(){
$this->selectedConservation = Conservation::query()
->where('sender_id',Auth::user()->id)
->orwhere('reciever_id',Auth::user()->id)
->first();
}
public function viewMessages($conservationsId){
$this->selectedConservation =
Conservation::findorFail($conservationsId);
}
public function render()
{
$conservation = Conservation::query()
->where('sender_id',Auth::user()->id)
->orwhere('reciever_id',Auth::user()->id)
->get();
return view('livewire.messaging',[
'conservation' => $conservation,
]);
}
resources\views\livewire\messaging.blade.php
#foreach ($conservation as $conservations)
<a href="#" wire:click.prevent="viewMessages({{ $conservations->id}} )">
<div class="user-card rounded bg-dark bg-opacity-10 mb-1">
<div class="mx-2">
<div class="d-flex pt-3">
<img class="rounded-circle" width="48px" height="48px" src="{{Config('wfh.file').$conservations->reciever->avator}}" alt="">
<div class="notification-text ms-3 w-100">
<span class="username fw-bold">{{$conservations->reciever->full_name}}</span>
<span class="float-end small"></span>
<p class="mt-1 text-muted">You: </p>
</div>
</div>
</div>
</div>
</a>
#endforeach
Check out the documentation on Dom Diffing Issues. It looks like you need to add a wire:key="{{ $conversations->id }}" attribute into your a tag so that Livewire can track changes to the list of conversations.

October CMS: AJAX form

My aim is to update a partial to show course dates when a date range is specified and submitted.
I have a function that works as expected.
user selects a start date
user selects an end date
the user clicks search
results are logged to the console
Here is the function
function onFetchDataFromServer()
{
$course = Course::findOrFail( $this->param('id') );
$start = Input::get('start_date');
$end = Input::get('end_date');
$dates = $course->coursemetas->whereBetween('date', array($start, $end));
return $dates;
}
Here is the markup
<form class="row gx-3 align-items-center" data-request="onFetchDataFromServer" data-request-success="console.log(data)"">
<div class="col-12 col-lg pxp-has-left-border">
<div class="input-group mb-3 mb-lg-0">
<span class="input-group-text"><span class="fa fa-calendar-o"></span></span>
<input type="date" class="form-control" id="startPicker" name="start_date" placeholder="Choose a start date">
</div>
</div>
<div class="col-12 col-lg pxp-has-left-border">
<div class="input-group mb-3 mb-lg-0">
<span class="input-group-text"><span class="fa fa-calendar-o"></span></span>
<input type="date" class="form-control" id="endPicker" name="end_date" placeholder="Choose an end date">
</div>
</div>
<div class="col-12 col-lg-auto">
<button type="submit">Search dates</button>
</div>
</form>
So the rather than logging the results to the console, I now would like to update a partial.
I have a partial in the view called 'course/metas'.
Can someone please help me?
Thanks in advance.
You can try something like this. Check the documents here.
This is for a page's PHP section:
function onFetchDataFromServer()
{
$course = Course::findOrFail( $this->param('id') );
$start = Input::get('start_date');
$end = Input::get('end_date');
$dates = $course->coursemetas->whereBetween('date', array($start, $end));
$this['dates'] = $dates;
return [
'#myDiv' => $this->renderPartial('coursemetas')
];
}
This is for component plugin:
function onFetchDataFromServer()
{
$course = Course::findOrFail( $this->param('id') );
$start = Input::get('start_date');
$end = Input::get('end_date');
$dates = $course->coursemetas->whereBetween('date', array($start, $end));
$this->page['dates'] = $dates;
return [
'#myDiv' => $this->renderPartial('#coursemetas')
];
}
Note the # sign sent with the renderPartial as this tells the framework to look inside the plugin folder for the partial. Or you can specify the partial path by component and partial name like this return $this->renderPartial('course::coursemetas');.

Error message "The GET method is not supported for this route. Supported methods: POST." in laravel 8

Following is my controller. Method ProjectsView is to view all the listings. The second method BackendProjectSearch is for searching of projects. The first page of search result is displayed properly, but when we click on next page it gives the error "The GET method is not supported for this route. Supported methods: POST."
What should I do ?
public function ProjectsView(){
$projects = projects::orderBy('id','ASC')->paginate(15);
return view('backend.projects.projects_view',compact('projects')); }
public function BackendProjectSearch(Request $request){
$request->validate(["search" => "required"]);
$item = $request->search;
$projects = Projects::where('project_name','LIKE',"%$item%")->paginate(15);
return view('backend.projects.projects_view',compact('projects')); }
Following are the routes for both the methods :
Route::post('/backend/project/search', [ProjectsController::class, 'BackendProjectSearch'])->name('backend.project.search');
Route::get('/view', [ProjectsController::class, 'projectsView'])->name('projects.view');
View code :
<div class="col-md-8">
<div class="header-navsearch">
<form class="form-inline mr-auto" method="post" action="{{route('backend.project.search')}}">
#csrf
<div class="nav-search">
<input type="search" name="search" class="form-control header-search" placeholder="Search projects…" aria-label="Search">
<button class="btn btn-primary" type="submit"><i class="fa fa-search"></i></button>
</div>
</form>
</div>
</div>
The route for this request should be post, not get.
Example
Route::post(-----);
Also, make sure to insert a CSRF token while making the request
it means you now cannot do something like the following.
Instead, you have to do something like...
<form action="{{ route('example') }}" method="POST">
#csrf {{-- According to the version of laravel --}}
{{-- Your other codes --}}
<button type="submit" class="">Submit</button>
</form>
You have to use the below code
return redirect()->route('projects.view')->with(['projects' => $projects]);
Your route might be little change
Route::get('/view/{projects?}', [ProjectsController::class, 'projectsView'])->name('projects.view');
and In your controller, you have to change function like this
public function ProjectsView($projects = null){
if($projects!=null){
return view('backend.projects.projects_view',compact('projects'));
}
else{
$projects = projects::orderBy('id','ASC')->paginate(15);
return view('backend.projects.projects_view',compact('projects'));
}

how to pass the text value to controller in <a> format?

I have to pass the value to controller page using link format.
My view page code for link:
<form action="<?=site_url('Account_Master/Tax_Save')?>" method="POST">
<head><h5><center>TAX SLAB ENTRY</center></h5><button type="submit" class="btn bg-slate"><i class="icon-file-plus position-left"></i>Ok</button>
<a id="button" method="POST" href="<?=site_url('Account_Master/get_data')?>" class="btn bg-info"><i class="icon-book3 position-left"></i> View All</a>
</head>
<div id="item1">
Tax Type: <input type="text" style="height: 28px; width:250px; " id="taxtype" name="taxtype">
</div>
When i clicked the view all button type link the value of the tax type should be pass to controller page.But i have written code to post the value but the value is not passed.
My controller code:
public function get_data(){
$tax = $this->input->post('taxtype');
print_r($tax);
$data['query']= $this->db->query("SELECT * FROM tax where taxtype ='$tax' ")->row();
$this->load->view('Account_Master/Tax_Setting1', $data, FALSE);
}
I have so far tired this code the value of the taxtype is not passed to the controller
hello I hope there is a problem with your code if I may say
Edited Part
Base on getting the input value which is not possible on button click can be done using jquery js library
html file
<form id="form" action="<?php echo site_url('Account_Master/Tax_Save');?>" method="POST">
<head>
<h5>
<center>TAX SLAB ENTRY</center>
</h5>
<button type="submit" class="btn bg-slate">
<i class="icon-file-plus position-left"></i>
Ok
</button>
<a id="button" href="<?php echo site_url('Account_Master/get_data/');?>" class="btn bg-info">
<i class="icon-book3 position-left"></i>
View All
</a>
</head>
<div id="item1">
Tax Type:
<input type="text" style="height: 28px; width:250px; " id="taxtype" name="taxtype">
</div>
</form>
Place this code just before your closing body tag
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#form').on('click', '#button', function(event){
event.preventDefault();
var form_box = $(this).parents('#form'),
tax_value = form_box .find('input').val(),
link_url = $(this).attr('href'),
url = link_url+tax_value;
form_box.attr('action', url);
form_box.submit()
})
})
</script>
Then in your controller,
either you do this
public function get_data($tax_value){
$tax = $tax_value;
print_r($tax);
$data['query']= $this->db->query("SELECT * FROM tax where taxtype ='$tax' ")->row();
$this->load->view('Account_Master/Tax_Setting1', $data, FALSE);
}
OR
public function get_data(){
$tax = $this->input->post('taxtype');
print_r($tax);
$data['query']= $this->db->query("SELECT * FROM tax where taxtype ='$tax' ")->row();
$this->load->view('Account_Master/Tax_Setting1', $data, FALSE);
}
I hope this help you if not let me know your argument okay... I am here to help

Adding Avatar Image to Profile Laravel 5

i want build an Profile Picture Avatar Upload and display it in the Profile for every user.
Buts dont work with my method.
My Avatar Upload code:
<div class="form-group">
<div class="form-group">
<label for="exampleInputFile"><img src="/img/photos.png" height="80" width="80"> Upload Avatar:</label>
<input type="file" id="exampleInputFile" name="profileimage"></font></br>
</div>
</div>
Code where everyone see it in Profile:
<div class="pull-left margin-left-25">
#if($user->profileimage == false)
<img src="/img/icon.png" height="80" width="80">
#endif
#if($user->profileimage == true)
<img src="{{$user->profileimage}}" height="80" width="80">
#endif
ProfileController image content (Dont work for me):
if ($request->hasFile('image')) {
$file = $request->file('profileimage');
$size = $request->file('profileimage')->getSize();
if ($size > 500000) {
session()->flash('errormessage','Image is too large');
return redirect()->back()->withInput();
}
if (substr($file->getMimeType(), 0, 5) !== 'profileimage') {
session()->flash('errormessage','File is not an image');
return redirect()->back()->withInput();
}
if ($file->isValid()) {
$path = $request->profileimage->store('uploads','public');
} else {
session()->flash('errormessage','Image is not valid');
return redirect()->back()->withInput();
}
}
if ($request->image !== null) {
$product->image = $path;
}
What i have done wrong?
Thanks!
Why don't use Validator class?It will be so much easier than what you have coded. As the following,
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:500000',
]);
Add the above code inside the method in which you store the file and do your things.
It will do the validation for you, then continue whatever you want to do with the file. For more options please check the link provided.
Also, in your HTML code. You need to have a form in first place, action and its method, so your code should be:
<div class="form-group">
<div class="form-group">
<form action="{{ route('profile'}}" method="post">
<label for="exampleInputFile"><img src="/img/photos.png" height="80" width="80"> Upload Avatar:</label>
<input type="file" id="exampleInputFile" name="profileimage"></font></br>
</form>
</div>
</div>
And in your web.php, you should have the following line:
Route::get('/URL', 'ProfileController#MethodName')->name('profile');

Resources