princeoo7

princeoo7

Member Since 3 Years Ago

Experience Points
8,460
Total
Experience

1,540 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
17
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 2
8,460 XP
Nov
11
2 weeks ago
Activity icon

Replied to Getting Null / Empty When Using Intervention In Laravel Controller

can anyone help with the masking issue I am facing ?

Nov
09
2 weeks ago
Activity icon

Replied to Getting Null / Empty When Using Intervention In Laravel Controller

I got it working after adding below:

$img->encode();

But now masking feature is not working :(

Activity icon

Started a new Conversation Getting Null / Empty When Using Intervention In Laravel Controller

I am trying to use the mask function but I am not able to get the image I think due to which I am getting NULL or EMPTY as result.

Whats working for me:

	return base64_encode(file_get_contents("assets/images/default-company-logo.png"));
        

Whats not working for me:

	$img = Image::make("assets/images/default-img.png")->resize(200,200);
        return base64_encode($img);

no error and nothing shown. Even log file is empty :(

Nov
07
3 weeks ago
Activity icon

Started a new Conversation How To Generate Random Coordinates Around Given Coordinates With Faker

I want to try placing markets on the google map and for that I want random lang and long but around a given real life coordinates how to generate those in faker ? below is the code I am using and I always end up in sea for some reason :P

$lang = 33.7490;
$long = -84.3880;

"langtitude" => $faker->latitude($min = ($lang-mt_rand(0,20)), $max = ($lang+mt_rand(0,20))),
                    "longitute" => $faker->longitude($min = ($long-mt_rand(0,20)), $max = ($long+mt_rand(0,20))),

Please help in this situation.

Oct
25
1 month ago
Activity icon

Started a new Conversation What To Do Of Functions Is Present In Every Model ?

I have this bunch of code repeated in every model. How can i optimize my models !

public function creator () {
        return $this->belongsTo(User::class, 'creator_id');
    }

    public function moderator () {
        return $this->belongsTo(User::class, 'moderator_id');
    }


    public function getActive()
    {
        return $this->active()->get();
    }

    public function scopeDeactive($q)
    {
        return $q->where('status_id', Status::Deactive);
    }

    public function getDeactive()
    {
        return $this->deactive()->get();
    }

    public function scopeBlocked($q)
    {
        return $q->where('status_id', Status::Blocked);
    }

public function getStatusAttribute() {
        return status($this->status_id);
    }



Oct
22
1 month ago
Activity icon

Replied to When Checking For Is Post Favorite, Returns False Even When The Post Is Favorite !

also is it not the same to do like below ?

...
return $this->favorites->contains("id", 1);
 ...
Activity icon

Replied to When Checking For Is Post Favorite, Returns False Even When The Post Is Favorite !

Correct ! I was actually checking for user_id form favorites table ...

Activity icon

Started a new Conversation When Checking For Is Post Favorite, Returns False Even When The Post Is Favorite !

I have post where I want to have a boolean value which reflects whether current post is my favorite or not. below is the code for the same in post model.

public function favorites()
    {
        return $this->belongsToMany(User::class, 'favorites', 'post_id', 'user_id')->withTimeStamps();
    }
    
    
    public function getIsMyFavAttribute()
    {
        return $this->favorites->contains("user_id", 1);
    }

in output I can see my name in the favorite users list but the boolean status shown is false. What am I doing wrong where ?

User Id take for checking it as of now is 1 as shown in above code.

Oct
16
1 month ago
Activity icon

Replied to Why Is My Double / Float Values Casted As Rounded Integer In Model !

at the app end in dart we can do value.toDouble() or Double.parse(value) but the real issue is if we are already processing the price at the server end then, why are we force to do it again at the app end. How is that efficient ?

Activity icon

Replied to Why Is My Double / Float Values Casted As Rounded Integer In Model !

I also tried casting the value but no help here also !

link : https://laravel.com/docs/8.x/eloquent-mutators#attribute-casting

protected $casts = array(
        "price" => "decimal:2",
    );
Activity icon

Replied to Why Is My Double / Float Values Casted As Rounded Integer In Model !

no issue on frontend and its a flutter app. UI wise the issue is that some product will show $14.99and some where $146 where it should have been $146.00. also if I pass the value as string, I need to convert it to double at the app end which is not needed.

Activity icon

Replied to Why Is My Double / Float Values Casted As Rounded Integer In Model !

as answered below end result is as same as first results without 2 decimal points. also this is only the case with values where we have number ending with 2 zero's and not with anything like 1499 or 1233. it works there were I get 14.99 and 12.33 respectively without any issues. Is laravel skipping it if we have zero as decimal values ?

Activity icon

Replied to Why Is My Double / Float Values Casted As Rounded Integer In Model !

yes on the front end its stored and processed as double. that's the reason I need it in that form itself.

Activity icon

Replied to Why Is My Double / Float Values Casted As Rounded Integer In Model !

@sinnbeck it gives me the result in desired form but in string format :( and if you say then also add floatval, we are back to square one which is the original result.

I have tried below already before posting it here:

public function getPriceAttribute(){
        return floatval(number_format($this->attributes["price"] / 100, 2));
    }
Activity icon

Started a new Conversation Why Is My Double / Float Values Casted As Rounded Integer In Model !

I am saving my price value in table as cents instead of dollar so e.g. is 14.99 = 1499 in db.

Now in my model I am doing as below for get the real value:

public function getPriceAttribute(){
        return $this->attributes["price"] / 100;
    }

now for 1499 it works and gives me 14.99 but the same is not working for 41600 which gives me 416. same is with other values where the figure ends with 2 zero's. I don't want to do the checks of the frontend and attach the .00 to it there.

How to get those 2 decimal points even in this case in json ?

Oct
15
1 month ago
Activity icon

Replied to Call To Undefined Method Illuminate\Database\Eloquent\Relations\HasMany::stocks() Error

@sinnbeck my bad I was using ProductResource and so I had to add it their.

Activity icon

Replied to Call To Undefined Method Illuminate\Database\Eloquent\Relations\HasMany::stocks() Error

@sinnbeck I was able to get the seeders working but now its not displaying data after been appended to the api call.

protected $appends = ['attributes', 'variants', 'status'];

public function getVariantsAttribute() {
        return $this->variants()->get();
    }

public function variants() {
        return $this->hasMany(ProductCombination::class)->with(['stocks']);
    }

any thing wrong here ?

Activity icon

Started a new Conversation Call To Undefined Method Illuminate\Database\Eloquent\Relations\HasMany::stocks() Error

I am getting Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::stocks() error. What is wrong with my logic ?

below code is working:

$product->variants()->create([
                "combination_string" => "cs".$sku,
                "sku" => $sku,
                "price" => $faker->randomNumber(mt_rand(2,5)),
                "unique_string_id" => $faker->uuid,
                "available_stock" => $stock,
            ]);

below is not working :(

$product->variants()->stocks()->create([
                "total_stock" => $stock,
                "unit_cost" => $uprice,
                "unit_cost" => $stock * $uprice,
            ]);

Product Model

class Product extends Model
{
  public function variants() {
        return $this->hasMany(ProductCombination::class);
    }  
}

Product Combination Model

class ProductCombination extends Model
{
    use HasFactory;

    public function stocks() {
        return $this->hasMany(ProductStocks::class)->withTimestamps();
    }
}

Activity icon

Replied to How To Filter Data To Be Displayed In An Api Call

@automica no it only gives me {} as output for values attribute.

But I got it working as below after posting the above line here :P

$this->attributeValues->value,

Oct
14
1 month ago
Activity icon

Replied to How To Filter Data To Be Displayed In An Api Call

yes I forgot about that ;)

Oct
13
1 month ago
Activity icon

Replied to How To Filter Data To Be Displayed In An Api Call

@automica I am getting null as that is also a relationship based value.

but if I do return parent::toArray($request) in ProductAttributeResource I get the below answer:

0	
- name	"color"
- attribute_values	
- value	"#b82e1c, #e8d984, #148bc4, #fbc33a, #0f6c54"

if I do :

return [
            "name" => $this->name,
            "value" => $this->attribute_values,
        ];

I get below output:

0	
name	"color"
value	null

so the value is null for $this->attribute_values.

Now If I do :

"value" => ProductAttributeValue::where("id", $this->id)->first()->value,

Then only I get the desired output:

{"data":[{"id":1,"title":"Enim illo aut.","slug":"enim-illo-aut.","attributes":[{"name":"color","value":"#b82e1c, #e8d984, #148bc4, #fbc33a, #0f6c54"},{"name":"size","value":"6, 7, 8, 9, 10, 11, 12"},{"name":"brand","value":"34"},{"name":"description","value":"Sit totam quos nobis sed. Sit nulla accusamus laudantium voluptatibus error. Autem deserunt aspernatur ex et saepe. Minima reiciendis repellendus et molestiae."}],"created_at":"2020-10-12T10:55:34.000000Z","updated_at":"2020-10-12T10:55:34.000000Z"},{"id":2,"title":"Necessitatibus delectus.","slug":"necessitatibus-delectus.","attributes":[{"name":"color","value":"#ba94e8, #64a995, #71daa4, #28086a, #5963fe"},{"name":"size","value":"6, 7, 8, 9, 10, 11, 12"}],"created_at":"2020-10-12T10:55:34.000000Z","updated_at":"2020-10-12T10:55:34.000000Z"}]}

is their a better way to do this ?

Activity icon

Replied to How To Filter Data To Be Displayed In An Api Call

Now the issue is in ProductAttributeResource where I am not able to access attribute_values.

return [
            "name" => $this->name,
            "value" => $this->attribute_values->value,
        ];

Activity icon

Replied to How To Filter Data To Be Displayed In An Api Call

Can you make an example based on my code ?

I got this when I tried to do the given:

Exception
Property [id] does not exist on this collection instance. 

I added below then I got the output but only one record:

public function toArray($request)
    {
        // return parent::toArray($request);
        return [
            "id" => $this[0]->id,
            "title" => $this[0]->title,
            "slug" => $this[0]->slug,
            "attributes" => $this[0]->attributes,
            "created_at" => $this[0]->created_at,
            "updated_at" => $this[0]->updated_at,
        ];
    }

How I called it in my controller:

public function index(Request $request) {
        return new ProductResource(Product::latest()->limit(2)->get());
    }

UPDATE:

got it working with below code:

public function index(Request $request) {
        return ProductResource::collection(Product::latest()->limit(2)->get());
    }

and removing the key form the return in resources.

Activity icon

Started a new Conversation How To Filter Data To Be Displayed In An Api Call

Below is my api output at the moment.


0	
id	1
title	"Enim illo aut."
slug	"enim-illo-aut."
created_at	"2020-10-12T10:55:34.000000Z"
updated_at	"2020-10-12T10:55:34.000000Z"
attributes	
0	
id	1
product_id	1
name	"color"
created_at	"2020-10-12T10:55:34.000000Z"
updated_at	"2020-10-12T10:55:34.000000Z"
attribute_values	
0	
value	"#b82e1c, #e8d984, #148bc4, #fbc33a, #0f6c54"
1	
id	2
product_id	1
name	"size"
created_at	"2020-10-12T10:55:34.000000Z"
updated_at	"2020-10-12T10:55:34.000000Z"
attribute_values	
0	
value	"6, 7, 8, 9, 10, 11, 12"
2	
id	3
product_id	1
name	"brand"
created_at	"2020-10-12T10:55:34.000000Z"
updated_at	"2020-10-12T10:55:34.000000Z"
attribute_values	
0	
value	"34"
3	
id	4
product_id	1
name	"description"
created_at	"2020-10-12T10:55:34.000000Z"
updated_at	"2020-10-12T10:55:34.000000Z"
attribute_values	
0	
value	"Sit totam quos nobis sed. Sit nulla accusamus laudantium voluptatibus error. Autem deserunt aspernatur ex et saepe. Minima reiciendis repellendus et molestiae."
status	
code	2
value	"Active"

What I want to achieve is as below:

	
0	
-id	1
-title	"Enim illo aut."
-slug	"enim-illo-aut."
-created_at	"2020-10-12T10:55:34.000000Z"
-updated_at	"2020-10-12T10:55:34.000000Z"
-attributes	
--0	
---name	"color"
---value	"#b82e1c, #e8d984, #148bc4, #fbc33a, #0f6c54"
--1	
---name	"size"
---value	"6, 7, 8, 9, 10, 11, 12"
--2	
---name	"brand"
---value	"34"
--3	
---name	"description"
---value	"Sit totam quos nobis sed. Sit nulla accusamus laudantium voluptatibus error. Autem deserunt aspernatur ex et saepe. Minima reiciendis repellendus et molestiae."
-status	
--code	2
--value	"Active"

How can I do it ?

I have 3 tables involved as below:

  1. Product Table
  2. Product Attributes Table
  3. Product Attributes Value Table

Relations as per model are:

  1. Product Mode:

    protected $appends = ['attributes', 'status'];
   
    public function getAttributesAttribute() {
        return $this->attributes()->get();
    }

    public function attributes() {
        return $this->hasMany(ProductAttribute::class)->with(['attributeValues']);
    }

  1. Product Attribute Model :
public function attributeValues() {
        return $this->hasMany(ProductAttributeValue::class);
    }

How should I achieve the expected output ?

Oct
12
1 month ago
Activity icon

Started a new Conversation Product Attributes And Attrubutes Value Table Complications

I have 4 tables in my database.

  1. Product
  2. Product Attributes
  3. Product Attributes Value
  4. Product Combinations

I have a question where table 2 and 3 are related.

for example I have 3 colors and 4 size for an product that makes a combination of 12 variety.

should I have 12 records in product attribute value table i.e. 3 record of color and 4 record of size or 1 record for each color and size respectively where all the variety are store as JSON or separated via comma ",".

There might also be a situation where we have 3 colors but each color don't have 4 size some color can only have 1 or 2 size also. How should I handle this via Eloquent Methods.

Sep
27
2 months ago
Activity icon

Replied to Image Manipulation In Laravel Controller And Storing It As Base64 String In Db

I know how to do image to base64 but image manipulation is something i am not familiar with !

Activity icon

Started a new Conversation Image Manipulation In Laravel Controller And Storing It As Base64 String In Db

I am stuck with a problem in a flutter project where I need to display a image as google map marker. I can show base64encoded image there or even a normal image. Issue is that it needs to have a shape polygon with a border.

  1. the solution to that was to either create a widget and use it, but this solution don't support the image output.
  2. another solution is to store the image with border and polygon shape as base64encode string and use it directly.

1st solution is not progressing so looking forward to second solution.

my simple question is how to do this in laravel controller when a user uploads a image, either square or rectangle or something.

any suggestions or code that can be shape is appreciated :)

below image is the demo for expectation and current output:

https://pasteboard.co/Jt0xd2i.png

Sep
21
2 months ago
Activity icon

Replied to How To Access Time Stamp In Api Controller For Pivot Table

I clearly said I need it in api controller so the data needs to be part of api json output

anyways the issue is solved.

Sep
19
2 months ago
Activity icon

Started a new Conversation How To Access Time Stamp In Api Controller For Pivot Table

As the title for the question says, How can i access the timestamp for a pivot table.

My model for user:

public function histories() {
        return $this->belongsToMany(UserFeed::class, 'histories')->withTimestamps();
    }

API Call controller :

$records = Auth::user()
            	->histories()
		->latest()
		->paginate(config("app.rec_limit"));

But I cannot either see the pivot table nor the timestamp data for the records been fetched !

what I get is only history records and nothing else.

Sep
18
2 months ago
Activity icon

Replied to When Extending Socialite, VS CODE Gives Error But Composer Runs Fine.

@ismaile its SocialiteProviders/Manager related code only. but that custom provider needs to be integrated in to socialite so we need that extending for register method only.

Sep
15
2 months ago
Activity icon

Started a new Conversation When Extending Socialite, VS CODE Gives Error But Composer Runs Fine.

Cannot declare class App\Providers\SocialiteServiceProvider because the name is already in use

this is the error I am getting when I am trying to extend the socialite for a custom provider.

full code:


<?php

namespace App\Providers;

use Laravel\Socialite\SocialiteServiceProvider;
use App\Socialite\Socialite;

class SocialiteServiceProvider extends SocialiteServiceProvider
{
    public function register()
    {
        $this->app->singleton('Laravel\Socialite\Contracts\Factory', function ($app) {
            return new Socialite($app);
        });
    }
}

should I be worried ? or it's just the IDE trying to warn me with the issue ...

Activity icon

Replied to Why And Int Variable Is Return Sometimes As String In Json Format In Api ?

@automica yes this can be used as in the models. my question was regarding a custom function where I am using (int) as of now. but this is also an answer for me.

Activity icon

Replied to Why And Int Variable Is Return Sometimes As String In Json Format In Api ?

@sinnbeck I was using this only but was thinking if their might be something else so for link from the model and the model answer is also below. its bad that we cannot have multiple answers and answer... :/

Activity icon

Started a new Conversation Why And Int Variable Is Return Sometimes As String In Json Format In Api ?

I am using below code to get status output :

if (! function_exists('status')) {
    function status($code) {
        $record  =  Status::getInstance(intval($code));
        return [
            'code' => $code,
            'value' => $record->description,
        ];
    }
}

output:

"status": {
                "code": 2,
                "value": "Active"
            }

but sometimes i get output as:

"status": {
            "code": "2",
            "value": "Active"
        }

if you see the code value in both the output, one is int as originally intended. Second one is a String value. Why is this happening ? how to stop this?

Sep
09
2 months ago
Activity icon

Started a new Conversation How To Access Personal Access Client ID And Client Secret In An Api Call

This one is a tough question as to what I have been seeking for months and when found, this is what next I am stuck at.

I am using coderello/laravel-passport-social-grant

Article with instruction : https://hivokas.com/api-authentication-via-social-networks-for-your-laravel-application

Their are 5 Important parameter which I need to create or update a user based on social media platform and then fetch a access_token.

  1. grant_type which is always social.
  2. client_id is the Personal Access Client ID.
  3. client_secret is the Personal Access Client Secret.
  4. provider which is social media platform like facebook, google or github.
  5. access_token this one is a thing which providers provide via their login button process.

I need to provide a way to perform this call via mobile app. Issue is 1st and 4th are static value so no issue. found is way to get 5thalso though it's not recommended but as of now its what I can do.

real issue is 2nd and 3rd. How can I obtain them? I cannot store those values in the mobile app. any way that we can get this values in the controller itself and do something that doesn't require this parameters.

the link which provides with access_token is domain/oauth/token form passport.

anyway out here ?

Aug
30
2 months ago
Activity icon

Started a new Conversation Group Columns Is Illegal Issue On Live Server But Not On Local Server

Facing below Issue on Live server but not on local server.

SQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause  on shared hosting

If I turn off strict mode in config/database.php it works on live server. My question is why this behavior when strict = true on both side.

Activity icon

Replied to Adding Limit Inside WITH Clause In Laravel Gives Null / Empty Array

@michaloravec can or cannot ? I didn't followed your statement...

Activity icon

Replied to Adding Limit Inside WITH Clause In Laravel Gives Null / Empty Array

@sinnbeck I have also tried below and still same result, just now the place where Videos are empty has changed.

$categories = Category::whereHas('videos', function($q){
                return $q->active()->limit(3);
            })->with(['videos' => function($q){
                return $q->active()->limit(3);
            }])->active()->limit(config('app.rec_limit'))->get();

Aug
29
2 months ago
Activity icon

Replied to Adding Limit Inside WITH Clause In Laravel Gives Null / Empty Array

@sinnbeck below is the code

    public function scopeActive($q)
    {
        return $q->where('status_id', Status::Active);
    }
Activity icon

Started a new Conversation Adding Limit Inside WITH Clause In Laravel Gives Null / Empty Array

How to limit number of records for the with clause in laravel!

Below code works and gives me all records for videos clause:

$categories = Category::with(['videos' => function($q) {
                return $q->with('translations')->active();
            }])->active()->latest('id')->limit(config('app.latest_limit'))->get();

Below code gives empty array for videos clasue:

$categories = Category::with(['videos' => function($q) {
                return $q->with('translations')->active()->limit(3);
            }])->active()->latest('id')->limit(config('app.latest_limit'))->get();

I found that some videos array have data. I.e. I tried using has or whereHas but its only working with with else gives error.

Important Thing to remember

public function videos () {
        return $this->belongsToMany(VideoFeed::class, 'category_video_feed', 'category_id', 'video_feed_id');
    }

its a belongsToMany relationship.

Aug
24
3 months ago
Aug
19
3 months ago
Activity icon

Replied to Any Optimize Way For The Given Create Or Update Elquoent Record ?

@martinbean and what about the moderator thing ? should I use the same function or do it in other function ?