Posts

Showing posts with the label laravel

Laravel Job not recognizing object property

Laravel Job not recognizing object property I am passing a request to a job class to send an email for a contact form. The issue is that I cannot directly access the property. I set the $request in the constructor as $this->request = $request; $this->request = $request; In the handle() method, I do this: handle() Log::info( 'job-contact-request', [ 'request' => $this->request ] ); the log spits out: [2018-06-30 14:07:34] local.INFO: request {"request":"[object] (AppEventsContactRequestValidated: {"request":{"client_name":"Daniel","client_email":"email@email.com","client_phone":"1234567891","client_text":"blargle carble darble zarble"},"socket":null})"} Which shows that the client_email is set. But when I try to access $this->request->client_email , I get: $this->request->client_email [2018-06-30 14:15:30] local.ERROR: Undefin...

Laravel casting exponent to float not working

Laravel casting exponent to float not working I have a very small number 0.00000064 that has the datatype of double(20,8) . I am seeing the number as 6.4E-7 . 0.00000064 double(20,8) 6.4E-7 In my model I am trying to cast column as follows: protected $casts = [ 'total_crypto_balance' => 'float' ]; but I am still receiving that exponent number back. to receive the number 0.00000064 in view and not the exponent 6.4E-7 . 0.00000064 6.4E-7 What am I doing wrong here? Possible duplicate of php- floating point number shown in exponential form – Namoshek Jul 1 at 7:26 @Namoshek - not really, nothing to do with Laravel casting. YET - if you can derive an answer from that into a viable Laravel eloquent solution, I will vote you as answer. – erezt Jul 1 at 7:29 ...

IoC not being resolved automatically

IoC not being resolved automatically I'm implementing repositories in my app. In my PresupuestoController (Presupuesto = Estimate in spanish) PresupuestoRepo gets injected in the constructor: <?php namespace AppHttpControllers; use IlluminateHttpRequest; use AppModelsPaciente; use AppRepositoriesPresupuestoRepository; class PresupuestosController extends Controller { protected $presupuestoRepo; public function __construct(PresupuestoRepository $presupuestoRepo ) { $this->presupuestoRepo = $presupuestoRepo; } /** * Show the form for creating a new resource. * * @return IlluminateHttpResponse */ public function create(Paciente $paciente) { $presupuesto = $this->presupuestoRepo->createNew($paciente); dd($presupuesto); return view('presupuesto.edit', compact('paciente')); } } So far so god. It works. But now I need to inject a dependency in the PresupestoRepo itself, Paciente...

store foreign key as zero instead of it's value

store foreign key as zero instead of it's value I have a table that all the values are foreign keys ,when I store these values it save it as zero not the value that I chose , public function create() { $type=type::query()->pluck('type'); $color=color::query()->pluck('colore'); $region=region::query()->pluck('country'); $size=size::query()->pluck('size'); $brand=brand::query()->pluck('company'); //$price=new_product::query()->pluck('price'); return view('sale',compact('type','color','region','size','brand')); } public function store(Request $request) { new_product::create($request->all()); return redirect()->route('sale.index'); } the model: class new_product extends Model { protected $table = 'enter_new_product'; protected $fillable = ['type_id', 'color_id', 'region_id', 'size_...

PHP join 2 arrays of same key value

PHP join 2 arrays of same key value I'm wondering how to solved this. I have 3(three) arrays that contained nested values in the "data" key like this: array:3 [ 0 => array:3 [ "status" => "Terkirim" "warna" => "lightgreen" "data" => array:12 [ 0 => 0 1 => 0 2 => 0 3 => 0 4 => 0 5 => 0 6 => 3 7 => 0 8 => 0 9 => 0 10 => 0 11 => 0 ] ] 1 => array:3 [ "status" => "Selesai" "warna" => "lightblue" "data" => array:12 [ 0 => 0 1 => 0 2 => 0 3 => 0 4 => 0 5 => 0 6 => 3 7 => 0 8 => 0 9 => 0 10 => 0 11 => 0 ] ] 2 => array:3 [ "status" => "Selesai" "warna" => ...

Laravel Eloquent how to join on a query rather than a table?

Laravel Eloquent how to join on a query rather than a table? I want to achieve this in Laravel: SELECT * FROM products JOIN (SELECT product_id, MIN(price) AS lowest FROM prices GROUP BY product_id) AS q1 ON products.id = q1.product_id ORDER BY q1.lowest; I wrote this, but clearly there is something wrong: $products = new Product(); $products = $products->join( Price::whereNotNull('price')->select('product_id', DB::raw('min(price) as lowest'))->groupBy('product_id'), 'products.id', '=', 'product_id' )->orderBy('lowest')->get(); The error I got: ErrorException in Grammar.php line 39: Object of class IlluminateDatabaseEloquentBuilder could not be converted to string. I'm currently using join(DB::raw('(SELECT product_id, MIN(price) AS lowest FROM prices WHERE price IS NOT NULL GROUP BY product_id) AS q1'), 'products.id', '=', 'q1.product_id') as a workaround. Just won...

Laravel morphedByMany where condition and count

Laravel morphedByMany where condition and count I have two tables: Posts and Pages that share one table for tags (morphToMany). My tables and relations: Table: Tags id, name public function posts() { return $this->morphedByMany('AppPost', 'taggable'); } public function pages() { return $this->morphedByMany('AppPage', 'taggable'); } Table: Posts id, name, active public function tags() { return $this->morphToMany('AppTag', 'taggable'); } Table: Pages id, name, active public function tags() { return $this->morphToMany('AppTag', 'taggable'); } How can I get all tags and count from both tables where pages.active and posts.active I tried this query but this query returns only tags that are in both models: Tag::whereHas("posts", function($q) { $q->where("posts.active", "=", 1); })->whereHas("pages", function($q) { $q->where("pages.active", "=", 1); }...

Why is my image not storing in a specified folder in Laravel 5.6?

Why is my image not storing in a specified folder in Laravel 5.6? In my form, I asked for an image to upload. Then I already validated it and it works. But the file is not stored in the uploads folder. Here's a snippet of my ProductController: public function store(Request $request) { // Validate fields $this->validate($request, [ 'product_name' => 'required', 'product_price' => 'required', 'product_desc' => 'required', 'product_img' => 'image|required' ]); // Upload image if($request->hasFile('image')) { app()->make('path.public/uploads'); $image = $request->image; $image->move('uploads', $image->getClientOriginalName()); } /*// Save the data into database Product::create([ 'name' => $request->product_name, 'price' => $request->product...

Laravel insert or update array, multiple rows

Laravel insert or update array, multiple rows Hello guys im stuck multiple row insert or update update working fine but how to make inside of update insert new row Iwant just in edit.blade.php -> if row exists update or just create new one Hello guys im stuck multiple row insert or update update working fine but how to make inside of update insert new row Iwant just in edit.blade.php -> if row exists update or just create new one new row insert image Controller public function update(Request $request, $id) { $post = Anime::find($id); $post->anime_name = $request->input('anime_name'); $post->anime_namesecond = $request->input('anime_namesecond'); $post->anime_synopsis = $request->input('anime_synopsis'); $post->anime_studio = $request->input('anime_studio'); $post->anime_duration = $request->input('anime_duration'); $post->age_rating = $request->input('age_ra...

How to upload Composer to DirectAdmin (sharedhost)

How to upload Composer to DirectAdmin (sharedhost) For my laravel project I see that it is required to have composer on the server. I have downloaded composer to my machine, but I don't know what that means to do it for the server. How can I accomplish this? Can you ssh into the server? – user2094178 Sep 16 '15 at 16:41 i just learned ssh so im not sure how to do that. Can you explain? – Ricki Moore Sep 16 '15 at 16:58 First you must find out with your hosting if you have ssh enabled. – user2094178 Sep 16 '15 at 17:17 ...

How to maintain Oauth2 State in Laravel Passport

How to maintain Oauth2 State in Laravel Passport I am trying to implement Laravel Passport in my project but i can't found how to maintain Oauth2 State. In Laravel passport official documentation not get enough information about Oauth2 state. I am trying to implement Oauth2 authentication with Anuglar6 and Laravel . In oauth2 documentation, there are "state" to prevent CSRF protection. "The client MUST implement CSRF protection for its redirection URI. This is typically accomplished by requiring any request sent to the redirection URI endpoint to include a value that binds the request to the user-agent's authenticated state (e.g., a hash of the session cookie used to authenticate the user-agent). The client SHOULD utilize the "state" request parameter to deliver this value to the authorization server when making an authorization request. " https://tools.ietf.org/html/rfc6749#section-10.12 ...