Category : foreach

I’m trying to create a pagination in my search result. I have one queries in my repository like: public function getFilteredVehicles($id,$pax,$categories,$search_type,$from_date,$to_date) { $vehicles = Vehicle::whereHas(‘destinations’, function($q) use($id){ $q->where(‘destination_id’,$id) ->where(‘active’,1); }) ->paginate(1); if($search_type == ‘disposal’ || $search_type == ‘pnd’) { $vehicles = $vehicles->where(‘registered_location’,$id); } if($categories) { $vehicles = $vehicles->where(‘vehicle_categoryid’,$categories); } return $vehicles; } The returned result ..

Read more

tenho alguns resultados no banco e preciso alinhar eles de acordo com a imagem abaixo. Mas não sei nem por onde começar. Estou fazendo em Laravel 5.8. enter image description here <table style="border-collapse: collapse; width: 100%;" border="0"> <tbody> @foreach ($equipe as $key => $a) <tr> <td style="width: 50%;"> <p style="text-align: center;"><strong>{{$a->admin->name}}</strong></p> <p style="text-align: center;">Controladora Municipal</p> ..

Read more

I hope you guys are okay. I’m putting together a customer edit form with PHP and I’ve reached a point where I can’t go any further. I have the following situation I need to populate a with some values ​​from a standard array Categories [ [ ‘id_category’ => 1, ‘name_category’ => ‘Foo’ ], [ ‘id_category’ ..

Read more

I have 5 items ( 3 items on first row & 2 items on 2nd row ) that loads something like this Here’s my sample blade code <div class="row"> @if( !empty( $data ) ) @foreach( $data as $field ) <div class="col-lg-4 services-overview-section__item"> <div class="services-overview-section__item–image"> <a href="{!! url(‘services-detail/’.$field->slug) !!}"> <img src="{{url($field->banner_image) }}"> <div class="services-overview-section__item–overlay"> <h3>{!! $field->name ..

Read more

I’ve executed a query which can potentially return 18 collections that contain another 4320 subcollections/collection. In total 77.760 records. Because this is too much data I want to iterate over the collections and subcollections to make it smaller. Bar> I thought that while iterating over a subcollection, I would calculate the average value of 10 ..

Read more

im working on a join/find laravel DB to retrieve te correct data, but it is showing the last entry of the database repeated 13 times. I hope you can help me. Here is the code. in controller $joinCot = Cotizaciones::findOrFail($id); $joinCot = DB::table(‘cotizaciones’)->join(‘prod_cotizaciones’, ‘prod_cotizaciones.id_cotizacion’, ‘=’, ‘cotizaciones.id’) ->join(‘users’, ‘users.id’, ‘=’, ‘cotizaciones.id_usuario’) ->join(‘clientes’, ‘clientes.id’, ‘=’, ‘cotizaciones.id_cliente’) ->select(‘cotizaciones.id’, ..

Read more

I have a problem with Laravel 8 and I’m not sure how to identify the error. The following happens .. In my controller it looks like this: $var = model::where(‘name’, $name)->firstOrFail(); print_r($var) Print_r returns this to me here AppModelstest Object ( [table:protected] => tb_test [timestamps] => [connection:protected] => mysql [primaryKey:protected] => id [keyType:protected] => int ..

Read more

I am trying to import users in my database. My code . public function staffImport(Request $request) { $this->validate($request, array( ‘file’ => ‘required’ )); if ($request->hasFile(‘file’)) { $extension = File::extension($request->file->getClientOriginalName()); if ($extension == "xlsx" || $extension == "xls" || $extension == "csv") { $path = $request->file->getRealPath(); $spreadsheet = IOFactory::load($path); $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); // ..

Read more

I want to show audit trail data in datatables. column old_values and new_values are array in database. i’m using yajra-datatable. Old_values/new_values value in db something like this {"updated_at":"2021-05-03 09:30:17.248","var_allowance_1":"500.00",**"var_allowance_2":"300.00"**} But in the view, column old/new_values, it only show the latest array. for example only show var_allowance_2 = 300.00 instead of all value (i.e) updated_at = ..

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

I’m having trouble getting the quantities of the ordered products to update the stock quantity based on pivot table "order_items". Order Model public function items() { return $this->belongsToMany(Product::class,’order_items’, ‘order_id’, ‘product_id’)->withPivot(‘quantity’, ‘price’)->withTimestamps(); } OrderItem Model public function product() { return $this->belongsTo(Product::class); } Product Model public function orders() { return $this->belongsToMany(Order::class,’order_items’, ‘order_id’, ‘product_id’)->withPivot(‘quantity’, ‘price’)->withTimestamps(); } OrderController public ..

Read more

I created a function which calculating all UNIQUE posts in categories and their subcategories (UNIQUE because some posts can be in few different categories). But I know that it is inaccurate code. Please help me to construct it on right way. So it will accept the unlimited level of subcategories. Thank you so much in ..

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 have segments. There are categories that segments have. Each segment consists of 3 categories and the middle segment is the main segment. How can I show them on the blade? I write code like this. $seg = DB::table(‘segments’)->get(); $categories = DB::table(‘categories’) ->join(‘category_translations’, ‘category_translations.category_id’, ‘categories.id’) ->select(‘categories.id’, ‘category_translations.category_name’) ->where(‘language_id’, $lan->id) ->get(); $seg_cat = DB::table(‘segment_categories’)->get(); @foreach($seg as ..

Read more

I have a list using React & Laravel. Using axios, I’m passing data like this on the frontend async function axiospost(order){ try { const response = await axios.post(‘http://localhost:8000/api/social/reorder/’, {order}); return response.data; } catch (error){console.error("Not able");} } But when testing my API using https://reqbin.com/, I have the following error : ErrorException: Invalid argument supplied for foreach() ..

Read more

when I am trying to add @foreach 3 times it’s repeating my data. how do I solve this? this is my code My Controller $students = Student::with(‘FeeScheem’,’IndFeeScheem’,’FeeGroup’,’FeeGroup1′) ->where(‘students.stu_id’, $students) ->get(); $this->students = $students; Eloquent Relationship public function FeeScheem() { return $this->hasOne(FeeScheem::class, ‘fs_id’, ‘stu_fee_scheem_id’); } public function IndFeeScheem() { return $this->hasOne(IndividuallyFeeScheem::class, ‘id’, ‘stu_ind_fee_scheem_id’); } public function ..

Read more

**@foreach($posts as $post)** <div class="card"> <img class="card-img-top" src="…" alt="Card image cap"> <div class="card-body"> <h5 class="card-title">**{{$post->title}}**</h5> <p class="card-text">**{{$post->description}}**</p> <p class="card-text">**{{$post->price}}**</p> </div> </div> **@endforeach** i want to create 4 inline cards to display all post. (4 cards on each line) i tried to put the past code in <div class="card-group"> **here** </div> but res result is many ..

Read more