Laravel validation: how to get optional fields in the validated result array?

i’m validating request with required and optional fields. When the request does not contain the optional field, it’s skipped and not returned in the validated() function, how can i get the optional field with empty string value in the returned array? input is [‘field_1’ => ‘test’] $validator = Validator::make($request->all(), [ ‘field_1’ => [‘required’], ‘field_2’ =>…

Laravel Eloquent – Dont return relationship

I got 2 models. File model: class File extends Model { public function user() { return $this->belongsTo(‘App\m_user’, ‘CODUSER’); } } And m_user model: class m_user extends Model { protected $table = ‘m_users’; public function file() { return $this->hasMany(‘App\File’, ‘id_user’); } } The tables are the follow: Files: id, id_user, name m_user: CODUSER, email I want…

Laravel web socket with pusher does not work

I am trying to use websocket with pusher for live notification. It was working perfect yesterday and suddenly it stopped working WebSocket connection to ‘ws://www.domain.com:6001/app/ap1?protocol=7&client=js&version=4.4.0&flash=false’ failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED But when I run $php artisan websockets:serve I get this in terminal: my bootstrap.js file look like this import Echo from ‘laravel-echo’ window.Pusher =…

Laravel ajax select example

i am trying to get qualification of a teacher in select, edit.js: success: function (data) { let quals = $(‘#qual_id’); $.each(data.qualifs, function(key, value) { quals.append(“<option value='”+ key +”‘>” + value + “</option>”); }); } controller: public function edit($id) { $teacher = DB::table(‘teachers’)->find($id); $qualifs = DB::table(‘qualif_teachers’) ->join (‘qualifs’,’qualif_teachers.qualif_id’,’=’,’qualifs.id’) ->select(‘qualifs.qual’,’qualifs.arb_qual’) ->where(‘teacher_id’, ‘=’ , $id) ->get(); return response()->json([…

How to join based on json column in Laravel QueryBuilder

posts table |id|value| |1 |hoge | |2 |fuga | |3 |piyo | some_posts table |id|post_ids| |1 |[1, 2] | |2 |[1] | |3 |[1, 2, 3]| I want to join using QueryBuilder. What should I do? That was not possible. DB::table(‘some_posts’) ->join(‘posts’, ‘some_posts.post_ids’, ‘posts.id’); SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: json =…

Sum child value monthly on Laravel

i have two table on my database I want to display budget data in table with total expenditure every month get from table expense like this here my Budget Model <?php namespace App; use Illuminate\Database\Eloquent\Model; class Budget extends Model { protected $table = ‘budget’; protected $primaryKey = ‘id’; protected $fillable = [‘description’, ‘budget’, ‘remaining_budget’, ‘deadline’];…

Move from xampp to Laravel Homestead: installation and opening projects

I want to move two Laravel projects from xampp local environment to Homestead environment. I followed laravel instructions, set up homestead and created a new project. However,getting an error message when trying to access ssh vagrant in the second homestead folder. My new installed laravel project is in directory C:\Projects\Project My homestead was installed in…