lavina

lavina

Member Since 3 Months Ago

Experience Points
1,040
Total
Experience

3,960 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
0
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 1
1,040 XP
Mar
09
4 weeks ago
Activity icon

Replied to Validating Unity Files

@stereoh the same error: The web gl must be a file of type: application/vnd.unity.

Activity icon

Started a new Conversation Validating Unity Files

Hello,

i am attempting to validate a file upload, the extension that in needs to have is *.unity3d.

I've been attempting multiple ways, and none of them have worked. Do i need to do a custom validation of extension to make it work or?

When i dd the mimetype of my file its: "inode/x-empty"

That, of course, is not enough

None of these work either:

            '' => 'file|required|mimes:application/vnd.unity',
            '' => 'file|required|regex:(unity3d)',
	    '' => 'file|required|mimes:unityweb',
	    '' => 'file|required|mimes:application/octet-stream',

Am i missing something, or do i need to make a seperate manual validation based on extension?

Feb
24
1 month ago
Activity icon

Replied to The Results Of A Failed Request

@sergiu17 Hello, an example: Controller

        public function register(Register $request)
        {
//never reached if validation fails
            dd($request);
    }
Register
    public function rules()
    {
        return [
            'name' => 'required|min:4',
            'email' => 'required|email',
            'password' => 'required|min:8',
            'c_password' => 'required|same:password',
            'is_admin'=>'required',
        ];
    }

If i had done it in a way that i validate in controller like:

        public function register(Register $request)
        {
        $this->validate($request, [
        'name' => 'required|min:4',
            'email' => 'required|email',
            'password' => 'required|min:8',
            'c_password' => 'required|same:password',
            'is_admin'=>'required',
        ]);
if ($this->validate <> true){
Alert::error('Error message')->flash();
}
}

I could just do add an alert, but now, it fails validation, and doesnt reach controller, so i have no idea where to catch the moment, impossible to do it in the request as it only returns requirments, what happens then??

Activity icon

Started a new Conversation The Results Of A Failed Request

Hello,

i am setting up my requests separately from my controller.

When i click a post button all my data is sent over, if it fails, it refreshes page, but i have no idea what the errors were. My controller thus is never reached, i would like to add the problems to an alert and then display them, but i am not sure at what point that can be done, any thoughts?

Feb
21
1 month ago
Activity icon

Started a new Conversation Getting Values From A Blade Form Select

Hello, i am attempting to retireve a selection made on a drop down list. I made the list like this:

    {!! Form::open(['action' => 'Api\[email protected]', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
    <div class="form-group">
        {{Form::label('product', 'Product')}}
        <br>
        {{ Form::select('product', $products) }}
    </div>
    {{Form::submit('Submit', ['class'=>'btn btn-primary', ''])}}
    {!! Form::close() !!}

But when i process it, the request only contains the id of the list itself which is useless for me, how can i get the text of the choice made?

Feb
19
1 month ago
Activity icon

Started a new Conversation Raw Input Into DB

Hello,

I've been attempting to mass insert rows into a table, and update if it already exists. This functionality is not supported by laravel(only for single row inserts as far as i've found), thus i am trying to write a raw insert, but it seems i am using the wrong sql sintax:

DB::insert('INSERT INTO
        products (name, description, created_at, updated_at)
        VALUES
        (\'name\',\'desc\',\'2020-02-19 09:03:45\',\'2020-02-19 09:03:45\'),
    (\'name\',\'desc\',\'2020-02-19 09:03:46\',\'2020-02-19 09:03:46\')
        ON DUPLICATE KEY UPDATE updated_at=\'2020-02-19 09:03:47\';
        ');

And duplicate key seems to only work on primary keys, which i let the table generate, thus each input is unique, how can i specify a different column to check duplicates for?

Feb
14
1 month ago
Activity icon

Replied to Backpack Crud Ordering On A Pivot Table

@mohaj Yes sir, works as expected, thank you very much!

Feb
13
1 month ago
Activity icon

Started a new Conversation Backpack Crud Ordering On A Pivot Table

Hello guys,

i am using backpack and attempting to display a crud admin panel for a pivot table(does not have its own id). But i get the error:

message: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'order clause' (SQL: select * from `section_user` order by 'id` desc limit 10)"

I attempted to add in setup:

$this->crud->orderBy('user_id');

but now its attempting to sort twice:

message: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'order clause' (SQL: select * from `section_user` order by `user_id` asc, `id` desc limit 10)"

How can i override and remove the sort by id?

Feb
12
1 month ago
Activity icon

Replied to Bulk Insert

@divdax "Object of class stdClass could not be converted to string"

Activity icon

Started a new Conversation Bulk Insert

Hello guys, i have a table in my database that contains 3 columns, x/y/z. And i have a json that looks like this:

array:3 [
  0 => array:1 [
    0 => {#649
      +"x": 0.50838017463684
      +"y": 0.47858500480652
      +"z": 0.41899466514587
    }
  ]
  1 => array:1 [
    0 => {#638
      +"x": 0.51666665077209
      +"y": 0.47777771949768
      +"z": 0.49444448947906
    }
  ]
  2 => array:1 [
    0 => {#642
      +"x": 0.0
      +"y": 0.0
      +"z": -2.3841857377249E-9
    }
  ]
]

How can i bulk insert of all them?

Jan
31
2 months ago
Activity icon

Started a new Conversation Using Where On A Relationship

Hello, i am trying to make a select through a relationship:

Model WorkSequence
    public function workSequenceModels()
    {
        return $this->hasMany('App\Models\WorkSequenceModel');
    }

I need the initial table and the relationship, thus i need to use a with, but i would like to limit my select on results found in WorkSequenceModel not on my initial model.

WorkSequence::with('workSequenceModels')->get();

How do i now put a constraint on the relationship instead of the WorkSequence select?

I attempted:

        return WorkSequence::find(1)->with(['workSequenceModels' => function ($query) {
            $query->where('platform_id', '=', '1');
        }])->get();

But this returns all workSequences, not just with id 1, not sure why though

Jan
28
2 months ago
Activity icon

Awarded Best Reply on Attaching Another Table After A HasManyThrough Relationship

Apparently the answer was as easy as it gets:

$workSequence = $this->stepAnimation::with('step.workSequence.categoryWorkSequence')->get();

As long as the relationships are set up, you can go as deep as you want

Activity icon

Replied to Attaching Another Table After A HasManyThrough Relationship

Apparently the answer was as easy as it gets:

$workSequence = $this->stepAnimation::with('step.workSequence.categoryWorkSequence')->get();

As long as the relationships are set up, you can go as deep as you want

Activity icon

Started a new Conversation Attaching Another Table After A HasManyThrough Relationship

Hello, i am trying to connect 4 tables together:

StepAnimation Model:
    public function steps()
    {
        return $this->hasManyThrough('App\Models\Step','App\Models\WorkSequence');
    }
    public function step()
    {
        return $this->belongsTo('App\Models\Step');
    }
Step Model:
    public function workSequence()
    {
        return $this->belongsTo('App\Models\WorkSequence');
    }
    public function stepAnimation()
    {
        return $this->hasMany('App\Models\StepAnimation');
    }
WorkSequence Model:
    public function categoryWorkSequence()
    {
        return $this->hasMany('App\Models\CategoryWorkSequence');
    }
    public function step()
    {
        return $this->hasMany('App\Models\Step');
    }
CategoryWorkSequence Model:
    public function workSequence()
    {
        return $this->belongsTo('App\Models\WorkSequence');
    }

I am currently selecting all the work sequences that have a step animation:

        $this->stepAnimation = New StepAnimation();
        $workSequence = $this->stepAnimation::with('step.workSequence')->get();

But now id like to attach all the categories to the worksequence, how do i need to extend the select for thatto happen?

Jan
27
2 months ago
Activity icon

Replied to Eloquent Model Selection

@ahmeddabak The way i got it to work was:

return Auth::user()->load('section.products');

But thanks for the push in the right direction!

Activity icon

Started a new Conversation Eloquent Model Selection

Hello, i have relationships between my models setup this way:

User:
    public function section()
    {
        return $this->belongsToMany('App\Models\Section');
    }
Product:
    public function sections()
    {
        return $this->belongsTo('App\Models\Section');
    }
Section:
    public function products()
    {
        return $this->hasMany('App\Models\Product');
    }
    public function user()
    {
        return $this->belongsToMany('App\Models\User');
    }

How do i now retrieve all products that belong to authenticated user?

Activity icon

Replied to Nesting Selects

@snapey surely you are correct, each subcategory should be nested in their parent category, sorry for the confusion, so a 2depth nest is needed, but no idea how to even make the first one

Activity icon

Started a new Conversation Nesting Selects

Hello, I am trying to make a select that returns an array inside of it:

 "products": [
        {
            "id": 1,
            "categories": [
            {
                "id": 1,
                "name": "category1",
                "product_id": 1
            },
"subcategories": [
            {
                "id": 1,
                "name": "subcategory1",
                "product_id": 1
            },
            {
                "id": 2,
                "name": "subcategory2",
                "product_id": 1
            }
            ]
            {
                "id": 2,
                "name": "category2",
                "product_id": 1
            }
"subcategories": [
            {
                "id": 1,
                "name": "subcategory1",
                "product_id": 1
            },
            {
                "id": 2,
                "name": "subcategory2",
                "product_id": 1
            }
            ]
            ]

        },

What i am currently doing is:

public function categoryList($companyId, $sectionId, $productId)
{
    $results = DB::table('work_sequences')->select('category_id as id', 'category_name as name', 'product_id')->distinct()->where('company_id', '=', $companyId)
    ->where('section_id', '=', $sectionId)
        ->join('products', function ($join) use($productId){
            $join->on('products.id', '=', 'work_sequences.product_id')
                ->where('products.id','=', $productId);
        })
        ->orderBy('category_id', 'asc')
        ->get();
    return response()->json(['categories' =>$results]);
  }

This returns categories split into multiple rows, while id only like to return only 1 row with all the data nested inside of it, how can this be achieved?

Jan
24
2 months ago
Activity icon

Replied to Elequent Model Setup Issue

$company id = [1,2], dd gives the same error message

Activity icon

Started a new Conversation Elequent Model Setup Issue

Hello,

i am attempting to select via elequent orm: I have the models setup: Company class:

    public function section()
    {
        return $this->hasMany('App\Models\Section');
    }

Section class:

    public function companies()
    {
        return $this->belongsTo('App\Models\Company');
    }

And then i am trying to retrieve all setions that belong to logged in user:

 public function getSectionId()
    {
        //return all sections that user belongs to
        $companyId=  Auth::user()->getCompanyIds(); //returns all sections ids ex: [1,2,3]
        echo($this->find($companyId)->section()->get());
exit;
}
echo($this->find(1)->section()->get());

returns all sections that belong to company 1, but when i try to call

echo($this->find($companyId)->section()->get());

I get the error: Method Illuminate\Database\Eloquent\Collection::section does not exist.

Is my relationship not correct or what am i doing wrong?

Jan
23
2 months ago
Activity icon

Started a new Conversation FindMany Not Breaking Down Array

Hello guys,

I have a function:

$test = ($this->companyList->pluck('company_id'));

It returns [1,2]

Then i try to use these results:

echo $this->test = Company::findMany([$test]);

It returns only the value at position 1 while if i do:

echo $this->test = Company::findMany([1,2]);

It returns both the values, what am i doing wrong here??

I attempted to do a print at the findMany function:

    public function findMany($ids, $columns = ['*'])
    {
        foreach ($ids as $id)
        {
            echo $id.'reached';
        }

And the result: [1,2]reached[{"id":1," .......... 1reached2reached[{"id":1, ..........

Why does that happen?

Jan
22
2 months ago
Activity icon

Replied to Laravel Eloquent Connecting Multiple Tables

@bony This is not using Elequent model relationships?

Activity icon

Replied to Laravel Eloquent Connecting Multiple Tables

Not sure what you mean @abhi321, i am trying to create a join using elequent models, so i would like to keep it in 1 line, there will be a lot of these and multiple joins later on as well.

Sql would be something like:

    $id=Auth::id();
    $results = DB::table('sections')
        ->join('section_and_users', function ($join) use ($id) {
            $join->on('sections.id', '=', 'section_and_users.section_id')
                ->where('section_and_users.user_id','=', $id);
        })
        ->get();
Activity icon

Started a new Conversation Laravel Eloquent Connecting Multiple Tables

Hello guys, i am attempting to make a select from and combine 3 tables into one:

class SectionAndUser
    public function sections()
    {        return $this->belongsTo('App\Models\Section');}
    public function users()
    {return $this->belongsTo('App\Models\User');}
class User 
    public function sectionAndUser(){return $this->hasMany('App\Models\SectionAndUser');}
class Section
    public function section_and_users(){return $this->hasMany('App\Models\SectionAndUser');}

These are the 3 models and their relationships, i would like to select starting from user all the sections he belongs to and then get the remaining info from the table sections. With the select:$sections = User::find($userId)->sectionAndUser()->get(); i get the result:

     "id": 1,
     "section_id": 1,
     "user_id": 133
 },

How do i now connect it with the sections table and pick up section name based on the section_id?

Jan
16
2 months ago
Activity icon

Replied to Testing Login Functionality

Once removed it now actually runs without error, even though I did not make any changes. Maybe clearing all caches helped, im not sure, but i was getting thrown to a 500 status every time i tried to comment out the $this->withoutMiddleware();

Activity icon

Replied to Testing Login Functionality

@sti3bas the error i now get is: Session store not set on request

dd returns: testing

Activity icon

Started a new Conversation Testing Login Functionality

Hey guys, i am testing my log in functionality and i keep getting an error im not sure how to fix:

public function testUserCanLoginWithCorrectCredentials()
{
    $this->withoutMiddleware();
    $user = factory(User::class)->create([
        'password' => bcrypt($password = 'test'),
    ]);
    $response = $this->post($this->loginPostRoute(), [
        'email' => $user->email,
        'password' => $password,
    ]);
    $response->assertRedirect('/home');
    $this->assertAuthenticatedAs($user);
}

My user is indeed authenticated, but the error is: Response status code [500] is not a redirect status code. If i dont run withoutMiddleware i get status code 419, because i am not throwing csrf token, what am i missing?

Jan
10
2 months ago
Activity icon

Replied to Unable To Confirm Auth::user

Hello, thanks for the help, apparently the issue was with backpack, it was overwriting my default authentication

Jan
09
2 months ago
Activity icon

Started a new Conversation Unable To Confirm Auth::user

Hello, I am implementing the passport auth in an existing application.

I ran : composer require laravel/passport php artisan migrate php artisan passport:install

Added: use HasApiTokens; to User model

Updated AuthServiceProvider with: public function boot() { $this->registerPolicies();

    Passport::routes();
}

And then updated config/auth return [ ....

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'passport',
        'provider' => 'users',
    ],
],

....

] My route is: Route::group(['middleware' => 'auth:api'], function(){ Route::get('/products', 'Api\[email protected]'); });

class CrudController extends Controller { public function allProductsList() { $id=Auth::id(); dd($id); return (Product::all()); } }

I access the link with bearer token in header And the return id is always empty, what am i missing??

Dec
18
3 months ago
Activity icon

Replied to Changing The Data Wrapping When Returning Json

Omg, yes, thank you!! :)

Activity icon

Replied to Changing The Data Wrapping When Returning Json

I tried that and it leads to an error:

Return value of App\Http\Controllers\CompanyController::index() must be an instance of App\Http\Resources\CompanyResourceCollection, array returned

Activity icon

Replied to Changing The Data Wrapping When Returning Json

And that wraps each of the id/name/descriptions combos together, but the whole bundle has no name

Activity icon

Replied to Changing The Data Wrapping When Returning Json

It returns: [ { "anyName": { "id": 7, "name": "Xzavier Koelpin", "description": "Nemo et vel voluptatem." } }, So the most outer wrap doesn't have a name

Activity icon

Replied to Changing The Data Wrapping When Returning Json

Wanted result would be: "anyName": [ { "id": 7, "name": "Xzavier Koelpin", "description": "Nemo et vel voluptatem." },

Activity icon

Replied to Changing The Data Wrapping When Returning Json

Found that in the documentation, but unsure how to wrap it after though

Activity icon

Started a new Conversation Changing The Data Wrapping When Returning Json

Hello guys, i am trying to return a select from my database, the resource collection class: public function toArray($request) {

    //return parent::toArray($request);
    return [
        'id' => $this -> id,
        'name' => $this -> name,
        'description' => $this ->description,
    ];
}

And then call in controller: public function index(): CompanyResourceCollection { return new CompanyResourceCollection(Company::all()); }

And i get a return of:

"data": [ { "id": 7, "name": "Xzavier Koelpin", "description": "Nemo et vel voluptatem." },

How can i change the wrapping name data to be anything i want?