Posts

Showing posts with the label laravel-5

Laravel Query with Multiple Tables Join and Multiple Join Fields

Laravel Query with Multiple Tables Join and Multiple Join Fields I'm trying to build a query to join multiple tables with multiple join fields. This is the code: $crew = DB::table('crew') ->join('aclist', function ($join){ $join->on(function($query){ $query->on('aclist.ac_config', '=', 'crew.config') ->on('aclist.ac_type', '=', 'crew.ac_type'); }); }) // Error happened after I add this indexform join script ->join('indexform', function ($join){ $join->on(function($query){ $query->on('indexform.config', '=', 'crew.config') ->on('indexform.ac_type', '=', 'crew.ac_type'); }); }) ->select('crew.*','ind...

laravel 5 : how to validate multi dimensional checkbox

laravel 5 : how to validate multi dimensional checkbox Hello i have the following in my view <table class="table"> <tbody> @foreach($products as $indexKey => $product) <tr> <td> <input type="checkbox name="order_products[{{$indexKey}}][id]" value="{{$product->id}}"/> </td> <td> <input type="text" name="order_products[{{$indexKey}}][quantity]" value=""/> </td> </tr> @endforeach </tbody> </table> and in my controller $this->validate($request,[ 'order_products'=>'required' ]) how can I validate that if one checkbox is checked, make sure the 'quantity' is not empty? i checked so many websites and nothing comes close to my answer, they are all using just one dimensional array. thank you! ...

How to use Laravel's hasManyThrough across 4 tables

How to use Laravel's hasManyThrough across 4 tables I have 4 tables with a structure and flow like this: User Accounts Contacts Orders The relationship is as follows: $user->hasMany('accounts')->hasMany('contacts')->hasMany('orders'); /** User Model **/ class User extend Eloquent { public function accounts(){ return $this->hasMany('Accounts'); } public function contacts(){ return $this->hasManyThrough('Contact', 'Account', 'owner_id'); } //how do I get this? public function orders(){ } } /** Account Model */ class Account extends Eloquent { public function $user(){ return $this->belongsTo('User'); } public function contacts(){ return $this->hasMany('Contact'); } } /** Contact Model **/ class Contact extends Eloquent { public function account(){ return $this->belongsTo('Account'); } pub...

Loop through object within an array Laravel

Image
Loop through object within an array Laravel I'm trying to loop through an object in an array in Laravel. I made a foreach to loop through my $request->newTags what is an object and I just return the key. my goal is to access each tag_name in my request object what has an array with the multiple indexes what contain the tag_name . foreach $request->newTags tag_name request object array tag_name foreach ($request->newTags as $tag) { return $tag; } and i get my response how can I access each tag_name? 2 Answers 2 Try this foreach ($request->newTags as $tag) { return $tag.tag_name; } Do you mean $tag->tag_name ? – Yosef Jul 1 at 7:11 $tag->tag_name becuase tag.tag_name return an error ...

Laravel 5.6 - Validate Numbers and spaces

Laravel 5.6 - Validate Numbers and spaces In Laravel 5.6 I am validating alphabetic characters and spaces only in regex like this.. 'name' => 'required|regex:/^[pLs-]+$/u', This works as far as I can see, I am now trying to validate numbers only and spaces like this.. 'telephone' => 'required|regex:/[0-9 ]+/', But this is not working and allows me to enter 'f4' where it should fail. Where am I going wrong? Try 'regex:/(^[0-9 ]+$)+/' – Vincent Decaux Jul 1 at 10:29 'regex:/(^[0-9 ]+$)+/' 1 Answer 1 [0-9 ]+ will match 4 in f4 [0-9 ]+ 4 f4 Try using anchors to assert the start and the end of the line ^ and $ ^ $ ^[0-9 ]+$ ^[0-9 ]+$ Note that this will also match whitespaces only because the ch...

A non-numeric value encountered Laravel5.5 on Migration

A non-numeric value encountered Laravel5.5 on Migration I am getting this error [ErrorException] A non-numeric value encountered when I give an artisan command php artisan migrate:fresh --seed . [ErrorException] A non-numeric value encountered php artisan migrate:fresh --seed This issue arised when I upgraded to php 7.1 in xammp. When I am not seeding the error does not occur. Below is the model factory $factory->define(AppClients::class, function (Faker $faker) { return [ 'firstname' => $faker->firstName($gender = null|'male'|'female'), 'lastname' => $faker->lastName($gender = null|'male'|'female'), 'email' => $faker->unique()->safeEmail, 'phone' => $faker->e164PhoneNumber(), 'country' => $faker->country(), 'university' => $faker->city() ]; }); Is there a workaround on this issue? Thanks in advance ...