laravel-5.3

Laravel 5.3: delete image from storage

六眼飞鱼酱① 提交于 2020-08-27 21:58:53
问题 I have a method which deletes a product and image that belongs to it, but I can not delete the image. Where am I going wrong with this? public function deleteProduct($ids) { foreach ($ids as $id => $value) { $product = Product::find($id); $productImage = $product->image_path; if ($productImage) { Storage::delete($productImage); $product->destroy($id); } } } I have a symlink between storage and public folder. Under storage images are located at e.g. - storage/app/public/images/products/4/image

Laravel 5.3: delete image from storage

不打扰是莪最后的温柔 提交于 2020-08-27 21:57:50
问题 I have a method which deletes a product and image that belongs to it, but I can not delete the image. Where am I going wrong with this? public function deleteProduct($ids) { foreach ($ids as $id => $value) { $product = Product::find($id); $productImage = $product->image_path; if ($productImage) { Storage::delete($productImage); $product->destroy($id); } } } I have a symlink between storage and public folder. Under storage images are located at e.g. - storage/app/public/images/products/4/image

Password authentication failed error on running laravel migration

南楼画角 提交于 2020-08-09 08:19:44
问题 I am trying to deploy my Laravel app on a DigitalOcean droplet. The droplet is setup with nginx, php7, and postgres, I follow up the tuts from DigitalOcean on how to set them up. Then I try to follow this tutorial on how to deploy the Laravel app using the git hook and so on. Now the app itself is up and running, I can access the pages and all. But I can't run php artisan migrate . I have been changing the database username, name, password on .env file, but I always get the exact same error:

Laravel 5.4: how to delete a file stored in storage/app

耗尽温柔 提交于 2020-08-01 09:30:11
问题 I want to delete a file that is stored in storage/app/myfolder/file.jpg. I have tried the following codes but none of this works: use File $file_path = url().'/storage/app/jobseekers_cvs/'.$filename; unlink($file_path); and use File $file_path = public_path().'/storage/app/myfolder/'.$filename; unlink($file_path); and use File $file_path = app_path().'/storage/app/myfolder/'.$filename; unlink($file_path); and also, File::Delete('/storage/app/myfolder/'.$filename); Please help. 回答1: You could

How to sort a collection of UTF-8 strings containing non-Latin chars in Laravel 5.3?

假如想象 提交于 2020-07-08 13:04:42
问题 Folks, I want to sort following nested collection by string alphabeticaly : $collection = collect([ ["name"=>"maroon"], ["name"=>"zoo"], ["name"=>"ábel"], ["name"=>"élof"] ])->sortBy("name"); I would expect : 1=> "ábel" 2=> "élof" 3=> "maroon" 4=> "zoo" I got instead : 1=> "maroon" 2=> "zoo" 3=> "ábel" 4=> "élof" I seen some PHP threads for this, but I am curious if there is any Laravel workaround for this. Thanks. 回答1: Here's a Solid way to do it: $blank = array(); $collection = collect([ [

How to get data passed from PUT method

情到浓时终转凉″ 提交于 2020-06-26 12:11:32
问题 I am creating an API for Laravel. I use the PUT method for updating data. I send data with Postman using the PUT method. In my controller, I got an empty array. How to access the passed data? In my route, I have: Route::put('vehicletypes/{id}','API\VehicletypeController@update'); In my controller: public function update(Request $request, $id){ print_r($request->all()); exit; } How to get the data passed in PUT method? 回答1: You are getting empty response because PHP have some security

How to get data passed from PUT method

只谈情不闲聊 提交于 2020-06-26 12:10:28
问题 I am creating an API for Laravel. I use the PUT method for updating data. I send data with Postman using the PUT method. In my controller, I got an empty array. How to access the passed data? In my route, I have: Route::put('vehicletypes/{id}','API\VehicletypeController@update'); In my controller: public function update(Request $request, $id){ print_r($request->all()); exit; } How to get the data passed in PUT method? 回答1: You are getting empty response because PHP have some security

How to remove duplicates in collection?

孤街浪徒 提交于 2020-06-24 21:34:11
问题 I have collection in Laravel: Collection {#450 ▼ #items: array:2 [▼ 0 => Announcement {#533 ▶} 1 => Announcement {#553 ▶} ] } It is the same items. How ti delete one of them? Full code is: public function announcements() { $announcements = $this->categories_ann->map(function ($c) { return $c->announcements->map(function ($a) { $a->subsribed = true; return $a; }); }); $flattened = $announcements->groupBy("id")->flatten(); return $flattened; } 回答1: $unique = $collection->unique(); 回答2:

How to remove duplicates in collection?

半城伤御伤魂 提交于 2020-06-24 21:33:34
问题 I have collection in Laravel: Collection {#450 ▼ #items: array:2 [▼ 0 => Announcement {#533 ▶} 1 => Announcement {#553 ▶} ] } It is the same items. How ti delete one of them? Full code is: public function announcements() { $announcements = $this->categories_ann->map(function ($c) { return $c->announcements->map(function ($a) { $a->subsribed = true; return $a; }); }); $flattened = $announcements->groupBy("id")->flatten(); return $flattened; } 回答1: $unique = $collection->unique(); 回答2:

Csrf token in vue component

有些话、适合烂在心里 提交于 2020-06-12 07:58:19
问题 I have Laravel 5.3 project with Vue.js integrated and I want to use CSRF-TOKEN in my form. Form html code is in Vue component file in resources / assets / js / bootstrap.js I have this: Vue.http.interceptors.push((request, next) => { request.headers.set('X-CSRF-TOKEN', MyApp.csrfToken); next(); }); then I have main vue file /resources/assets/js/app.js : require('./bootstrap'); Vue.component('callbackwindow', require('./components/callbackwindow.vue')); const app = new Vue({ el: '#app', data: