Category : loops

I’m trying to paginate my collection that I’ve generated with below codes $vehicles = Vehicle::whereHas(‘destinations’, function($q) use($id){ $q->where(‘destination_id’,$id) ->where(‘active’,1); })->get(); The collection i’ve recieved from above is looped again. foreach ($vehicles as $key => $vehicle) { # code… $perday_rate = $vehicle->destinations->where(‘id’,$destination_id)->first()->pivot->day_rate; $pernight_rate = $vehicle->destinations->where(‘id’,$destination_id)->first()->pivot->night_rate; $day_rate = $perday_rate*$days; $night_rate = $pernight_rate*$nights; $total_amount = $day_rate+$night_rate; $vehicle[‘total_amount’] = ..

Read more

i’m new in larevel and i have some problem when trying to use loop combines with html in View (syntax error, unexpected token "<", expecting end of file) (error in LINE SESSION(‘cart)!=null) This is my code: {!! $data= json_decode(session(‘cart’),true); @if(session(‘cart’)!=null) foreach($data as $item) <tbody> <tr> <td class="product-thumbnail"><img src="assets/img/product/1.jpg" alt=""></td> <td class="product-name"><a href="#">{{$item[0]->name}}</a></td> <td class="product-price"><span class="amount">{{$item[0]->promotion_price}} ..

Read more

I need help In a foreach loop I access to a pivot table but when I need print that information one time @foreach ($autoevaluacion as $dato) <tr> <td>{{$dato->nombre}}</td> @foreach ($dato->encuesta_desempenio as $rta) <td>{{json_decode($rta->pivot->evaluado)[0]}}</td> <td>{{$rta->pivot->respuesta}}</td> @endforeach </tr> @endforeach json_decode($rta->pivot->evaluado)[0] this I don’t need repeat, how i do it? Sourc..

Read more

I’d like to loop each $song with livewire component. Everything’s okay, buy styling is broken like that: Steps to reproduce VerificationSection.php <?php namespace AppHttpLivewire; use AppModelsSong; use LivewireComponent; class VerificationSection extends Component { public $songs; public function mount(){ $this->songs = Song::where(‘isVerified’, false)->get(); } public function render() { return view(‘livewire.verification-section’); } } livewire.verification-section.blade.php <div class="grid grid-cols-1 ..

Read more

DB::beginTransaction(); try { foreach ($values as $key => $val) { //First $id = DB::connection(‘otherDB’)->table(‘HEAD’)->insertGetId([‘val’ => $val]); foreach ($detail as $key => $valDetail) { // Second DB::connection(‘otherDB’)->table(‘DETAIL’)->insert([‘head_id’ => $id]); } // Third MyTable::where(‘val’, $val->id)->update([‘status’ => 1]); } DB::commit(); return ‘Success’; } catch (Exception $e) { DB::rollBack(); return ‘Not Success’; } Hi, I am a beginner. Here ..

Read more

I m new to laravel and making a search app for homeo remedies i am facing following problem $remAilProps = DB::table(‘remedies’) ->join(‘ailment_modules’, ‘remedies.id’, ‘=’, ‘ailment_modules.rem_id’) ->join(‘ailments’, ‘ailment_modules.ail_id’,’=’,’ailments.id’) ->join(‘ailment_modules as ail’,’ailments.id’,’=’,’ail.ail_id’) ->join(‘ailment_props’,’ail.ail_id’,’=’,’ailment_props.ail_id’) ->join(‘props’,’ailment_props.props_id’,’=’,’props.id’) ->join(‘props_values’,’props.id’,’=’,’props_values.props_id’) ->select(‘ailment’,’props’,’propsValue’) ->distinct() ->groupBy(‘propsValue’) ->keyBy(‘ailment’) ->where(‘remedies.id’,’=’,$id) ->get(); return view(‘layout.navitems.users’) ->with(‘ailment’,Ailments::all()) ->with(‘rem’,Remedy::where(‘id’,’=’,$id)->firstOrFail()) ->with(‘org’,Organs::all()) ->with(‘remedy’,Remedy::all()) ->with(‘remAilProps’, $remAilProps); } when i loop it blade view the ..

Read more

I have categories and posts.So i want to,each post line up for each other’s category.This is my code which i try in controller.Then i call in blade with foreach loop $smallpostsWithCat=array(); $postsWithCat=array(); $postsWithCatQuery = DB::table(‘posts’) ->join(‘post_translations’, ‘posts.id’, ‘post_translations.post_id’) ->join(‘language’, ‘post_translations.language_id’, ‘language.id’) ->where(‘language.local’, App::getLocale()) ->where(‘big_thumbnail’, 1)->latest(‘post_date’)->limit(1)->get(); $smallpostsWithCatQuery = DB::table(‘posts’) ->join(‘post_translations’, ‘post_translations.post_id’, ‘posts.id’) ->join(‘language’, ‘post_translations.language_id’, ‘language.id’) ->where(‘language.local’, ..

Read more

I have this code in blade: <tbody> @for ($i = 1; $i <= n; $i++) <tr data-nr="{{ $i }}" data-group="1"> <td rowspan="2">{{ $i }}</td> <td></td> </tr> <tr data-nr="{{ $i }}" data-group="2"> <td></td> </tr> @endfor </tbody> In html ouput is: <tr data-number="1" data-group="1"></tr> <td rowspan="2"><td> <tr data-number="1" data-group="2"></tr> <td></td> <tr data-number="2" data-group="1"></tr> <td rowspan="2"><td> <tr data-number="2" ..

Read more

I want store user settings right after the user logs inside. I want to achieve it through laravel jobs. I have done this inside the controller $setting_array = $this->setting->get(); foreach($setting_array as $list){ $user_data = [ ‘user_id’ => $this->nepo_user->id, ‘setting_id’ => $list->id ]; InsertUserSetting::dispatch($user_data); } and inside InsertUserSetting job I have public function handle() { $data ..

Read more

I’m trying to find a solution, I’m doing a carousel of 3 items per active item, and I’m doing a foreach, but I want that on the second slide of the carousel, 3 other elements to be shown. So here’s my code actually : <div class="carousel-inner"> <div class="carousel-item active"> <div class="mountains-formation slide-1 d-block" style="background-image: url( ..

Read more

view blade <input type="file" name="upload[0][front_image]" id="image" class="custom-file-input" multiple=""> <input type="file" name="upload[0][er_image]" id="image" class="custom-file-input" multiple=""> <input type="file" name="upload[0][wire_image]" id="image" class="custom-file-input" multiple=""> controller public function add_edit_pro_img(Request $req, $id = null){ if ($req->isMethod(‘post’)) { $data = $req->all(); $upload_img = $req->file(‘upload’); foreach ($upload_img as $files) { $product_image = new ProjectImages; $imgs = Image::make($files[‘front_image’]); $er_imgs = Image::make($files[‘er_image’]); $wire_imgs = Image::make($files[‘wire_image’]); ..

Read more

$products = $category – > products; foreach($params as $key => $item) { if ($key === ‘attribute’) { $attributes = $item; // dd($attributes); foreach($attributes as $subkey => $value) { // dd($subkey, $value); $attr_ids = ProductAttribute::where(‘name’, $subkey) – > pluck(‘id’) – > toArray(); // print_r($attr_ids); // dd($attr_ids); foreach($attr_ids as $attr_id) { $filtered_products = new Collection(); $filtered_products = ..

Read more

view laravel <input type="file" name="front_image[]" id="image" class="custom-file-input" multiple=""> <input type="file" name="er_image[]" id="image" class="custom-file-input" multiple=""> <input type="file" name="wire_image[]" id="image" class="custom-file-input" multiple=""> controller public function add_edit_pro_img(Request $req, $id = null){ if ($req->isMethod(‘post’)) { $data = $req->all(); //echo "<pre>"; print_r($data); die; if ($req->hasFile(‘front_image’) || $req->hasFile(‘er_image’) || $req->hasFile(‘wire_image’)) { //echo "yes"; die; $frontImg = $req->file(‘front_image’); //echo "<pre>"; print_r($frontImg); $erImg ..

Read more