Category : oop

I have two similar methods in my controller: First method: public function parseDataLayerEvent() { $events = $this->pixel_log->data[‘dataLayer’]; if (!is_array($events)) { throw new Exception(‘dataLayer is not an array’); } foreach ($events as $event) { if (!isset($event[‘event’])) { continue; } if (!isset($event[‘ecommerce’])) { continue; } if (!isset($event[‘ecommerce’][‘purchase’])) { continue; } $purchase = $event[‘ecommerce’][‘purchase’]; $validator = Validator::make($purchase, [ ..

Read more

I have two similar methods in my controller: First method: public function parseDataLayerEvent() { $events = $this->pixel_log->data[‘dataLayer’]; if (!is_array($events)) { throw new Exception(‘dataLayer is not an array’); } foreach ($events as $event) { if (!isset($event[‘event’])) { continue; } if (!isset($event[‘ecommerce’])) { continue; } if (!isset($event[‘ecommerce’][‘purchase’])) { continue; } $purchase = $event[‘ecommerce’][‘purchase’]; $validator = Validator::make($purchase, [ ..

Read more

I need to understand what’s going on with my model instance. I have setup and many-to-many relationship in my User model public function projects(){ return $this->belongsToMany(Project::class, ‘project_users’, ‘user_id’, ‘project_id’)->withPivot(‘role’)->withTimestamps(); } When a user logs in, I return an instance of the user model $user = User::where(’email’, $request->email)->first(); return response([ ‘message’ => ‘User Logged in’, ‘data’ ..

Read more

I have a simple questions but I cant find any answer in internet. class Product extends Model { use HasFactory; public function variants() { return $this->hasMany(Variant::class); } } >>> $p->variants(); => IlluminateDatabaseEloquentRelationsHasMany {#4331} >>> $p->variants; => IlluminateDatabaseEloquentCollection {#4310 all: [ AppModelsVariant {#4319 id: "1", name: "VariantOne", created_at: null, updated_at: null, quantity: "2", product_id: "1", }, ..

Read more

I’m comparing 2 tables in Laravel. The model’s class has this function in it: public function sampleTableReference() { return $this->hasOne(samepleTableReference::class, foreignKey:’otherColumnId’, localKey:’ColumnId’); } In the view, we have: <?php dd($collection->sampleTableReference()->dd())?> This outputs: "select * from `sample_table_reference` where `sample_table_reference`.`columnId` = ? and `sample_table_references`.`columnId` is not null and `sample_table_reference`.`deleted_at` is null array:1 [▼ 0 => 30 ] ..

Read more

I have DB table with following columns id|name|email|role|password|etc. And I want to restrict some content of my view page when the user isn’t admin(role type). I have the following code but something went wrong and I’m getting not awaited result. Code in my AuthServiceProvider Gate::define(‘restricted-view’,function($user){ return $user->role == ‘admin’; }); Code in my Controller $user ..

Read more

I am trying to pass "product_id" property value to Success method, to attach "product_id" value in pivot table. But I am not getting the value from "product_purchase_pay" method. Both method are inside same class. public function product_purchase_pay(Request $request) { $product_id = $request->id //product_id receiving from request } public function success(Request $request){ $pivot_user = User::find(Auth::id()); $pivot_product ..

Read more

I have a reservation system webapp with Laravel as the backend (everything is working fine, authorization, requests, editing users’ details and other objects’ too). I have special settings for editing business hours. I created a special class called Intervals that helps me calculate available hours, if given timestamp is available, returning all unavailable days based ..

Read more

I have an object called Logo, there is a setter in this object for the layout: public function setLayout(string $layout): void { $this->layout = $layout; } I create an instance of Logo and then a loop of different layouts: $logo = new Logo($request->name, $font, $symbol); foreach (Logo::getConstants() as $layout) { $logo->setLayout($layout); $newLogo = new LogoMaker($logo); ..

Read more

I’m having a hard time sending input data between classes. I have a class with a method that recieves a text input fields data that works normally: <?php namespace AppHttpControllerspostCode_related; use AppHttpControllersController; use IlluminateHttpRequest; use AppHttpRequestsestate_agent_relatedvalidationbranch_checkVal; class postCode_input extends Controller { public function retrieve(branch_checkVal $request) { $validated = $request->validated(); $user_input_postcode = $request->input(‘brach_postcode’); $postcode = str_replace(‘ ..

Read more

here is my function which get an array public function exportpdf(Request $request) { dd($request->school); $pdf = PDF::loadView(‘reports.sDPR’,[‘schools’=>$schools])->setPaper(‘a3’, ‘landscape’); return $pdf->download(‘School Details Reports.pdf’); } after printing, i got the following array in print how to convert the following array to $schools object i try with classic php $array=request->school; $schools=(object)$array; then return to view but it show ..

Read more