I am trying to store user info including a pic in Laravel 5.3. Here is the relevant code:
if ( isset($request->image) )
{$path = $request->file('image')->store('public/users');}
$user = User::find($request->id);
if (isset($path))
{$user->image = $path;}
$user->name = $request->name;
$user->email = $request->email;
$user->active = $request->active;
$user->admin = $request->admin;
$user->address = $request->address;
$user->country_id = $request->country_id;
if ($request->ageverified = 1)
{$user->ageverified = 1;}
if ($request->verifieddate <> '')
{$user->verifieddate = $request->verifieddate;}
$user->verify_notes = $request->verify_notes;
$user->publisher = $request->publisher;
$user->paypal = $request->paypal;
$user->proname = $request->proname;
if (isset($path)) {
$file = Storage::url($path);
$tpath = basename($path);
Image::make($path)->resize(100,
100)->save('public/users/thumbs/'.tpath);
$user->thumbnail = $tpath;
}
$user->save();
The image is stored OK but when I get to making the thumbnail I am getting:
NotReadableException in AbstractDecoder.php line 302: Image source not readable
I have tried everything but am really stuck!
I have sorted this out in a laracast forum - see https://laracasts.com/discuss/channels/laravel/53-image-source-not-readable
Related
I wrote these code for upload files through laravel 6.
But I only success for upload one file,even I am sure I got all files while uploading by check from dd($request->files)
in the begining the $index = 0 and in the end it change to 1,first round is ok but the it didn't continue to second run.
I don't know why,please help! thank you~
if($request->hasFile('files')){
$index = 0;
foreach($request->files as $key=>$file){
$originalName = $file[$index]->getClientOriginalName();
$size = $file[$index]->getClientSize();
$ext = $file[$index]->getClientOriginalExtension();
$newName = date('Ymd').mt_rand(100,999).$originalName;
$savePath = '/attachments/'.$newName;
$movePath = base_path().'/public/attachments/'.$newName;
$file[$index]->move(base_path().'/public/attachments',$newName);
$attachment = new attachment();
$attachment->bulletin_id = $bulletin->id; //already got this value before
$attachment->original_name = $originalName;
$attachment->name = $newName;
$attachment->type = $file[$index]->getClientMimeType();
$attachment->path = $savePath;
$attachment->size = ($size/1000);
$attachment->save();
++$index;
}
}
You try this way and it is simple
foreach($request->file('files') as $key=>$file){
$originalName = $file->getClientOriginalName();
$size = $file->getClientSize();
$ext = $file->getClientOriginalExtension();
$newName = date('Ymd').mt_rand(100,999).$originalName;
$savePath = '/attachments/'.$newName;
$movePath = base_path().'/public/attachments/'.$newName;
$file->move(base_path().'/public/attachments',$newName);
$attachment = new attachment();
$attachment->bulletin_id = $bulletin->id; //already got this value before
$attachment->original_name = $originalName;
$attachment->name = $newName;
$attachment->type = $file->getClientMimeType();
$attachment->path = $savePath;
$attachment->size = ($size/1000);
$attachment->save();
}
I created a store function on my controller. At the time I will enter data with just one submit, only indexed up to 40 data will be entered. While those 40 and above do not enter the database. Why did this happen? What's the solution? Please i need help.
Sorry for my bad English.
Thanks
I am use Laravel 5.6
public function store(Request $request)
{
//
foreach($request->quantity as $quantity){
if($quantity == NULL){
}
if($quantity != NULL){
$data = new KomponenOlahan;
$data->quantity = $quantity;
$harga_satuan_mu = Input::get('harga_satuan_mu');
$total = $quantity*$harga_satuan_mu;
$data->kode_proyek = Input::get('kode_proyek');
$data->nama_proyek = Input::get('nama_proyek');
$data->kode_panel = Input::get('kode_panel');
$data->nama_panel = Input::get('nama_panel');
$data->schedule_kirim = Input::get('schedule_kirim');
$data->nama_sales = Input::get('nama_sales');
$data->ukuran_panel = Input::get('ukuran_panel');
$data->ref = Input::get('ref');
$data->type = Input::get('type');
$data->komponen_bantu = Input::get('komponen_bantu');
$data->nama_komponen = Input::get('nama_komponen');
$data->spek = Input::get('spek');
$data->satuan = Input::get('satuan');
$data->diskon = Input::get('diskon');
$data->harga = Input::get('harga');
$data->pole = Input::get('pole');
$data->ka = Input::get('ka');
$data->ampere = Input::get('ampere');
$data->quantity = $quantity;
$data->harga_satuan_mu = $harga_satuan_mu;
$data->harga_satuan_mb = Input::get('harga_satuan_mb');
$data->harga_satuan_lb_oh = Input::get('harga_satuan_lb_oh');
$data->id_estimasi = Input::get('id_estimasi');
$data->nama_estimasi = Input::get('nama_estimasi');
$data->total = $total;
$data->trigger_bom = Input::get('trigger_bom');
$data->save();
}
}
My View
<td><input type="text" name="quantity[]" class="form-control"></td>
<td><input type="text" name="kode_proyek" hidden value="{{$panel->kode_projek}}">
etc....
My View
my view
You can save it first to array then use bulk insert.
Inserting data 1 by 1 will slow your application.
$insertArray = array();
foreach($request->quantity as $quantity){
if($quantity == NULL){
$insertArray[] = array(
'quantity' => $quantity,
'harga_satuan_mu ' => Input::get('harga_satuan_mu'),
.... // add other fields
)
}
}
KomponenOlahan::insert($insertArray);
I'm trying to addDays to a date using Carbon with Laravel, but I don't get why I'm receiving this error. I have checked some posts in StackOverflow, but no one has helped me to solve it.
This is my code:
$user = Auth::user();
$orders = DB::table('orders')->where('user_id', Auth::user()->id)->get();
$totalValue = 0;
$percentage = 0;
$currentDate = $carbon->now();
$currentDate = Carbon::parse($currentDate)->format('d/m/Y');
//$percentage = ($order->price * 0.05) / 30;
foreach($orders as $order) {
$nextDate = Carbon::parse($order->created_at)->format('d/m/Y');
if(1 == 1) {
$nextDate->addDays(1);
DB::table('orders')->where('user_id', Auth::user()->id)->update(['profit' => $order->profit]);
}
The error:
Try to add a day before change date format like below.
Carbon::parse($currentDate)->addDays(1);
or
Carbon::parse($currentDate)->addDay();
The simple way to add a day from today date is Carbon::now()->addDay();
Thanks.
I guess you are not saving your created_at date properly. Try following code.
$user = Auth::user();
$orders = DB::table('orders')->where('user_id', Auth::user()->id)->get();
$totalValue = 0;
$percentage = 0;
$currentDate = $carbon->now();
$currentDate = Carbon::parse($currentDate)->format('d/m/Y');
//$percentage = ($order->price * 0.05) / 30;
foreach($orders as $order) {
$nextDate = \Carbon\Carbon::parse($orders[0]->created_at)->format('d/m/Y');
$new_date = \Carbon\Carbon::createFromFormat('d/m/Y',$nextDate)->addDays(1)->toDateString();
if(1 == 1) {
//$nextDate->addDays(1);
$new_next_date = date('d/m/Y',strtotime($new_date));
DB::table('orders')->where('user_id', Auth::user()->id)->update(['profit' => $order->profit]);
}
I create my first module in Prestashop 1.7.4. This is my code:
public function createProductsObject()
{
$product = new Product;
$product->name = $productName;
$product->ean13 = '';
$product->reference = '';
$product->id_category_default = $getCategoryID;
$product->category = $getCategoryID;
$product->indexed = 1;
$product->description = $description;
$product->condition = 'new';
$product->redirect_type = '404';
$product->visibility = 'both';
$product->id_supplier = 1;
$product->link_rewrite = $link_rewrite;
$product->quantity = $singleStock;
$product->price = $price;
$product->active = 1;
$product->psoft_hurtobergamo_id = $productID;
$product->add();
$product->addToCategories($getCategoryID);
This function in not complite. But this is not important right now. Variable productName hase this value:
Array ( [0] => Test [1] => Test) )
Beacause I have two language. The problem is. Why I dont have the name after the product is create ?
thanks for help.
To resolve this problem I add new index to my array.
$productName = array('0' => '');
$link_rewrite = array('0' => '');
and then add values to array start from index 1. Because the first language has identity value set to 1. The second, 2.
for ($i = 1; $i <= $getNumberOfAvailableLanguage; $i++)
{
array_push($productName, $name);
array_push($link_rewrite, $clean1);
}
This is my controller in store function save for ministries table.
$ministries = new Ministry;
$ministries->country_id = $request->country_name;
$ministries->township_id = $request->township_name;
$ministries->city_id = $request->city_name;
$ministries->division_id = $request->division_name;
$ministries->ministryCode = $request->ministry_code;
$ministries->ministryName = $request->ministry_name;
$ministries->ministryNameMm = $request->ministry_mm_name;
$ministries->address = $request->address;
$ministries->phone = $request->phone;
$ministries->fax = $request->fax;
$ministries->email = $request->email;
$ministries->website = $request->website;
$ministries->save();
$ministries_id = $ministries->id;
this is save for other table(contact_persons)
for ($i=0; $i < count($request->position_id); $i++) {
$contact_persons = new ContactPerson();
$contact_persons->responsibility_id = $request->responsibility_id[$i];
$contact_persons->position_id = $request->position_id[$i];
$contact_persons->country_id = $request->email[$i];
$contact_persons->township_id = $request->email[$i];
$contact_persons->city_id = $request->email[$i];
$contact_persons->division_id = $request->email[$i];
$contact_persons->customer_id = $request->email[$i];
$contact_persons->address = $request->email[$i];
$contact_persons->home_phone = $request->email[$i];
$contact_persons->mobile = $request->email[$i];
$contact_persons->email = $request->email[$i];
$contact_persons->ministries_id = $ministries_id;
$contact_persons->save();
}
please how to solve and thanks.