laravel-5.5

How to get validation message in laravel 5.5

会有一股神秘感。 提交于 2019-12-10 15:41:18
问题 hi folks I'm working on Laravel 5.5 and here I need to display validation messages for my API upto now I have done like this $validator = Validator::make($request->all(),[ 'first_name' => 'email|required', 'last_name' => 'nullable', 'email' => 'email|required', 'mobile_no' => 'nullable|regex:/^[0-9]+$/', 'password' => 'required', ]); if($validator->fails) { $this->setMeta('status', AppConstant::STATUS_FAIL); $this->setMeta('message', $validator->messages()->first()); return response()->json(

Laravel File Storage delete all files in directory

此生再无相见时 提交于 2019-12-10 01:57:02
问题 Is there a way to delete all files in specific directory. I'm trying to clear all my files in my created folder backgrounds in storage\app\backgrounds but in docs seems no method for delete all. Storage::delete('backgrounds\*.jpg'); 回答1: I don't think if this is the best way to solve this. But I solved mine calling use Illuminate\Filesystem\Filesystem; Then initiate new instance $file = new Filesystem; $file->cleanDirectory('storage/app/backgrounds'); 回答2: use Illuminate\Support\Facades

Laravel Dusk: how to use in-memory DB for testing

荒凉一梦 提交于 2019-12-09 19:12:20
问题 What I've been trying is to use in-memory database while testing with Laravel Dusk . Here we have a file, .env.dusk.local , with the following values. DB_CONNECTION=sqlite DB_DATABASE=:memory: Here is a snippet of a browser testing file. class ViewOrderTest extends DuskTestCase { use DatabaseMigrations; /** @test */ public function user_can_view_their_order() { $order = factory(Order::class)->create(); $this->browse(function (Browser $browser) use ($order) { $browser->visit('/orders/' .

How to check if validation fail when using form-request in Laravel?

与世无争的帅哥 提交于 2019-12-09 03:24:37
问题 I am trying to write a CRUD for an API. However, when the validation fail, instead of redirecting the user to the home page, I want to return json based response with the errors. I am able to do that using the following code public function store(Request $request) { try { $validator = $this->getValidator($request); if ($validator->fails()) { return $this->errorResponse($validator->errors()->all()); } $asset = Asset::create($request->all()); return $this->successResponse( 'Asset was

Redirect automatically when user session expires in Laravel 5.5

拜拜、爱过 提交于 2019-12-09 02:05:18
问题 I want to redirect automatically to my login page when a user session expires using Laravel functions. I do redirect when a user try to access to another page and the session expires. I have set a lifetime which helps to log out automatically because of user's inactivity, and what I want is to redirect instantly when that session timeout. I tried using JavaScript to timeout but this is not functional when the user is using more than one page at time. I also tried using AJAX, sending requests

How to show selected value from database in dropdown using Laravel?

六眼飞鱼酱① 提交于 2019-12-08 11:26:42
问题 I want to show selected value from database into dropdown list on page load. My controller index function is : public function index() { $country_data =DB::table('country')->select('country_id','country_name')->get(); $profile_data= DB::table('profiles')->select('*')->where('id',$user_id)->first(); return view('profile_update',compact('profile_data','country_data')); } Column name in database for height is :Height My dropdown in profile_update.blade.php is <select class="select4" name=

Serialization of 'Closure' is not allowed when using queues

霸气de小男生 提交于 2019-12-08 10:40:03
问题 Here's my RequestMail.php file: protected $phone; /** * Create a new message instance. * * @return void */ public function __construct(Request $request) { $this->request = $request; $this->phone = $request->get('phone'); } /** * Build the message. * * @return $this */ public function build() { return $this->from('robot@bithub.tech') ->view('request') ->subject('Новая заявка на обмен криптовалют') ->with(['phone' => $this->phone]); } My controller: Mail::to('request@domain.com')->queue(new

Model filters based on the currently authenticated user

落花浮王杯 提交于 2019-12-08 10:38:02
问题 I am working on an app, in which each user is assigned a particular region. For example, user 1 belongs to a region 'Phoenix', user 2 to 'Scottsdale', and user 3 to 'Tempe'. The region of each user is defined in the region_id column. The app has 3 separate guards for 3 different user models (it's a marketplace with regional managers, providers, and customers). Virtually every model in the app has a region_id column, identifying to which region the resource belongs to. I would like to simplify

Remove index.php from URL of Laravel

痞子三分冷 提交于 2019-12-08 04:55:15
问题 I am using Laravel 5.5.12 in Linux Mint.I am using LAMP stack. I would like to remove index.php from URL. My mod_rewrite apache module enabled. My .htaccess file located in public folder and it contains following code. <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> Options +FollowSymLinks # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] # Handle Front

Laravel 5.5 - Validate Multiple Form Request - at the same time

末鹿安然 提交于 2019-12-08 03:32:26
The question is already asked here for a previous version of laravel and not yet answered. I have a html form which is validated using three different Form Request Validations . I am able to do this. But, the problem is, the form validations take place one by one. Not at the same time. If the first form request throws a validation error the form is returned to the view so rest of the two forms doesn't evaluated, hence a proper validation error can't be displayed to the user. What I want is : validate the form with the three form validation requests rules at the same time . Controller: public