OriOn

OriOn

Member Since 1 Year Ago

Experience Points
30,860
Total
Experience

4,140 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
246
Lessons
Completed
Best Reply Awards
10
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 7
30,860 XP
22 Aug
1 month ago

OriOn left a reply on Undefined Variable: Users

well there is a small typo in @mstrauss ' answer,

in the blade a s is missing in the foreach directive:

@foreach($users as $user)

OriOn left a reply on What Is Different Or Best Practices

Yes, in the case where you foreign key is what laravel expects it to be then you do not need to provide it in the relationship definition. I would also like to point out that there are other optional parameters to the hasMany and belongsTo methods then only the foreign key (you can find this out in the documentation or the source code the trait name is HasRelationships)

for the blade part, Your post will never have more than one owner because it is a belongsTo relation between the models $post->owner is the User Model of the id stored in the user_id field of the post object.

the use of parenthesis is for collections, for instance in your environment a user can have many posts so $user->posts() will be the collection of posts the user is the owner of. $user->posts()->first() will be the post object with the oldest created_at timestamp (unless otherwise ordered or sorted) $user->posts()->first()->title would reach for the title property of that post object.

hope it clarifies things for you.

OriOn left a reply on More Than One Listener On Events

if you edit the sequence of listeners do you observe the same result (only the first of the list is logging) or only SendOrderStatusChangeMail is logging?

on a side note I would like to say that I would personally not have the same approach here: I would not list listeners to a single event, if the logic dictates that 3 jobs have to be fired then I would queue those jobs into a single listener and let the server deal with the jobs at its convenience, especially if you are dealing with mail sending like it appears by the names you defined.

OriOn left a reply on Repeated Query Or Wrong Model Implementation?

with what I suggested above you could reach the last slotQuery related to the Slot by doing

$slot->slotQueries->first()
// returns the slot query or null

You could also use a forelse in the blade that would prompt the latest slot query or whatever you like if empty

@foreach($slots as $slot)
    <tr scope="row" class="">
        <td>{{ $slot->latestQuery()->date }}</td>
        <td>{{ $slot->latestQuery()->gnl }}</td>
        <td>{{ $slot->latestQuery()->gme }}</td>
        <td>{{ $slot->latestQuery()->created_at }}</td>
        @forelse($slot->slotQueries as $slotQuery)
            <td>{{ $slotQuery->id }}</td>
        @empty
            <td>no slot query</td>
        @endforelse
</tr>
@endforeach
21 Aug
1 month ago

OriOn left a reply on Blocking Other Users From Viewing Messages

@cronix just assumed the controller method you used to return the conversations was a show method.

the logic he suggested can be added on the existing method you are using,

what // other stuff for if the do have permission meant was the rest of your method goes here.

OriOn left a reply on Repeated Query Or Wrong Model Implementation?

Have you tried something like:

$slots = Slot::with(['slotQueries' => function ($query) { return $query->latest()->first(); }])->get();
18 Aug
1 month ago

OriOn left a reply on Call To Undefined Function Save()

You miss the parenthesis after you Menu class

public function store(Request $request) { 
  $menu=new Menu();
  $menu->restaurant_id=$request->get('restaurant_id');   
  $menu->value=$request->input('food_item');
  $menu->value=$request->input('price'); // Also you overwrite the line you just wrote
  $menu>save();

  return redirect('/restaurants')->withStatus(__('Restaurant successfully updated.'));
}
14 Aug
1 month ago

OriOn left a reply on Difference Between Jobs And Events

To my understanding an event is listening to a change while a job is creating one.

But then of course if you pick up on a change with an event it's also to do something with that .

I would use jobs in your context, it provides you with a control over the sequence of jobs that your workflow might require. Using events when updating multiple things at once could have some undesirable effects.

08 Aug
1 month ago

OriOn left a reply on Integrate Different Sources Of Notifications

Hello, Maybe I didn't catch all the details here but to me this really look different notification channels and could be handled within a Notification class.

what you really have here is multiple broadcast channel for a single entry. ok, the different channels do not emit necessarily the same fields but that's just logic within the different channels, no real need for a table storing these fixed configuration items.

I would look into creating new broadcasting channels to handle your variety of streams.

Also Notifications are sent to users so the Oauth variables could be appended to the users table directly and you would still be able to $user->notify()

OriOn left a reply on Delete Notification

Well like for any other model, you have the $notification->delete() method.

you can access a collection of notifications for a given user by doing $user->notifications()

From this point, you could narrow to the notification you want to delete and proceed with that.

$user->notifications()
    ->where('id', $notificationId) // and/or ->where('type', $notificationType)
    ->get()
    ->first()
    ->delete();
06 Aug
1 month ago

OriOn left a reply on How To Find Parent_id In Users Table

Hi there, it seems you are querying the related table and want to use the whereHas method docs

$users = Buy::with('user')->whereHas('user', function ($query) { return $query->where('parent_id', auth()->user()->id); })->latest()->paginate(25);;
15 Mar
6 months ago

OriOn left a reply on Converting Array Of Address Parts To A String

Wouldn't json_encode() be preferable over implode to turn your array into a string?

It saves you from building the string on one side to json_decode() it on the other (to later deal with the string..

OriOn left a reply on Logging In User Types

I meant not sure you can do that in the factory.

What I usually do is create all my type of users in the set up and then log in different one for different tests

Also since you are using this package, why create tables for different types of users? In the end aren't Student and Professor just roles for a single user model?

OriOn left a reply on Logging In User Types

I think you should return $this and not $user

For the rest you need to make sure the permission is created according to spatie instructions for testing (on their readme) Not sure if you can do that in your UserFactory->state()

Same goes for the role if you use them

14 Mar
6 months ago

OriOn left a reply on How Do You Manage A View That Is Getting Big Like This Going Out Of Control?

In addition of the first answer.

Your view should not be querying the database, that's the job of the controller.

Also laravel provides a $loop variable for in the loops so you don't have to make it yourself.

13 Mar
6 months ago

OriOn left a reply on Many To Many - Creating A Model For The Pivot Table To Get More Control ?

You can name it as it pleases you and overwrite the table name in the relationship definition.

Eloquent would look for a 'role_user' table for n to n relation between roles and users yes

OriOn left a reply on Many To Many - Creating A Model For The Pivot Table To Get More Control ?

Often there is no need for such model, even if the pivot table has extra columns... but it can be useful in more complex configuration though.

If you can already anticipate the need to only query the pivot table (without accessing either user or role) then you could need a model for it. If DB::table('role_user').... isn't sufficient

OriOn left a reply on Please Help Newbie Question, Inline Templates Vs Slots

Didn't you forget the inline-template in your opening tag ?

OriOn left a reply on Phpunit :: Laravel Redirect Upon Validation Failure

My bad @tykus thanks for correcting me

Also nice helper method, I might use it as well

OriOn left a reply on Phpunit :: Laravel Redirect Upon Validation Failure

You are specifying in your controller where it should redirect when validation succeeds and the record is created.

When the validation fails laravel redirects back and in your test case it is the home page because the last request before post was actingAs() which is a login and auth controller redirects to / on success.

A normal user would do a get request to the form to post it (in that case your assertion is true because back is then /posts/create) but this is not the case in your test case

10 Mar
6 months ago

OriOn left a reply on Database Is Not Updating

No, I think it's fine, it was just misleading out of your context.

any luck updating your axios request as I showed above?

OriOn left a reply on Database Is Not Updating

No I get that too now, but the route you are using in a resource controller is reserved for the store method and you are here trying to update so you should address your request to the good route.

see second reply

OriOn left a reply on Database Is Not Updating

hmm the question has been updated since I replied here... I'm not sure my first answer as any value

you are posting to api/mock while in fact you do want to patch api/mock/{mock}

use

axios.patch('api/mock/1', {
    subject: 'english',
        list: myJSON
 }).then().catch();

OriOn left a reply on Database Is Not Updating

Mocking is for testing, it is to be expected that the content is the same before and after a test is run so that you could validate your app without polluting your database

OriOn left a reply on Relationship / Get Model Above Current Model

You can do the same I detailed earlier for as many type of level you want.

I start to understand your setup, correct if I'm wrong:

a User can have both UserLevel and VendorLevel that reflect both their experience as user and vendor.

so if you adapt my code above for UserLevel and duplicate it for VendorLevel you can check both doing

    $nextUserLevel = \App\UserLevel::find($user->userLevel->id +1);
    $nextVendorLevel = \App\VendorLevel::find($user->vendorLevel->id +1);

OriOn left a reply on Relationship / Get Model Above Current Model

I'm not sure I understand why every level is a different level.

it could be a column of users or a second model for the levels if there is a need for that.

in that case User and Level would have a one to many relationship.

in you App\User.php class

public function level()
{
    return $this->belongsTo(Level::class);
}

in your App\Level.php class

public function users()
{
    return $this->hasMany(User::class);
}

different levels can be ordered by the level's id level id 1 would be the lowest. level id 2 would be superior...

to find what is the next level you would look for a level with an id greater by 1

    $nextLevel = Level::find($user->level_id + 1); // using the column level_id of the user's table
    // or
    $nextLevel = Level::find($user->level->id +1); // using the relationship we set above.

if that id doesn't exist then find will return null

OriOn left a reply on What Does A Namespace Actually Do In A Laravel Route ?

out of the box laravel uses the default namespace for the controller (the one in which artisan places it when you use the command make:controller App\Http\Controllers

if your application happens to have a lot of controller, Let's say you want to build Todo lists for your users we will call Task the model

we create a Todo folder in App\Http\Controllers

<?php

namespace App\Http\Controllers\Todo;

use App\Http\Controllers\Controller;

class TaskController extends Controller
{
    public function index() 
    {
        // ... 
    }
}

in that case in your routes/web.php to refer to that controller's index method you would have two options

    // without namespace
    Route::get('/todo', 'Todo/[email protected]');

    // with namespace
    Route::namespace('Todo')->get('/todo', '[email protected]');

I usually use that to keep the routes a simple a possible putting namespaces, name, middlewares on a parent group.

OriOn left a reply on Hello Fiends | How To Fix Property [id] Does Not Exist On This Collection Instance.

$products is a collection of Product and id is an attribute of Product not $products.

every items of products have id but not the collection

You might want to loop through your collection if you want to list all the Products it contains. with a foreach for example

25 Feb
6 months ago

OriOn left a reply on On Click Outside Of Some Element In Vue

24 Feb
6 months ago

OriOn left a reply on Prompt To Change Password If Default Password

Hi, You could check that in the controller. If the password is the default one, redirect to new password instead of home.

23 Feb
6 months ago

OriOn left a reply on Dynamic Configuration In Service Provider

If every user has is own different value then yes the database would be my preference here

OriOn left a reply on Delete And Edit Button As Modals

You could use bootstrap modal to display the edit form

about vue, the advantage would avoid you from reloading the page after submiting a delete or edit form. You do not need vue if you just want a modal edit form

OriOn left a reply on How Do I Query Three Tables To Send The Info To The View

Hello, It sounds to me like you want to have a look at eager loading.

it's more or less what you are doing for the likes except that it's adding it to the $friends collection. Your models need to be related though.

I guess friends are users,

users have many likes,

users have many comments

you can load a user, his likes and his comments like so:

\App\User::with('comments', 'likes')->find($userId);

now the same principle applies if you are querying many users, like via your friendship relation

18 Feb
7 months ago

OriOn left a reply on Best Way For Store Data In Database?

Hello, I had asked myself a similar question on a project. The way I went forward with was to only store users in the users table. And by user, understand people with credentials to log in the app. The rest would be stored as "contacts", "resources" or else..

15 Feb
7 months ago

OriOn left a reply on Email

By providing your .env file with the proper credentials. like:

MAIL_DRIVER=smtp
MAIL_PORT=
MAIL_HOST=
MAIL_USERNAME=
MAIL_PASSWORD=

also check the config/mail.php to get the full collection of variable to provide laravel with

13 Feb
7 months ago

OriOn left a reply on No Scheduled Commands Are Ready To Run | Empty

Hi there, I understand now better the problem, thanks for the clarifications. I believe the cron job is working fine but for some reasons yet to identify, scheduler:run do not identify any command as "due". I went back to [this episode] (https://laracasts.com/series/intermediate-laravel/episodes/1) in which Jeffrey explained a bit the set-up for cron and I think something that could give us a clue on what's going on is missing.

you mentioned your cron job is * * * * * cd /var/www/myfolder.com/ && php artisan schedule:run >> crontab.laravel

Laravel's documentation is specifying that schedule:run has 2 outputs the first one for logs and second for errors.

could you please update your cron job into * * * * * cd /var/www/myfolder.com/ && php artisan schedule:run 1>> crontab.laravel 2>> cronerrors.laravel

hopefully something pops in this last file

12 Feb
7 months ago

OriOn left a reply on I Keep Re-writing My Code Whenever I Learn Something New

I'm still learning new things with laravel on a daily basis (or almost) and this while building a respectable size application. It would be impossible for me to go over all these files to hunt down some "old style" code.

If it makes the app more robust, improve readability, why not.. the volume it represents should decide.

if it's just to implement a helper method you just heard about in the last laracast episode than no even if it's cool. Start to use it and make it your new standard that's good and later when you implement a new feature using an old file, then refactor while you are at it.

We will always learning new tips but only because we dig deeper for our projects, so I don't think doing over and over the same piece is helping you progressing (other than practicing/assimilating the new stuff)

OriOn left a reply on Mysql Connection Problems

You should do php artisan config:clear instead of cache:clear for the xml file edition.

11 Feb
7 months ago

OriOn left a reply on No Scheduled Commands Are Ready To Run | Empty

Since this problem is still open I was wondering what would happen if you would to place the content of the command that refuses to process into one that you said was working. Have you tried placing the content of the handle method into the handle method of elena:help ?

OriOn left a reply on Restore Function Return 404 Not Found

Route model binding returns 404 if you route to a soft deleted element.

public function restore($postId) {
    \App\Post::onlyTrashed()->findOrFail($postId)->restore();
}
10 Feb
7 months ago

OriOn left a reply on No Scheduled Commands Are Ready To Run | Empty

Last question because I'm running out of ideas here, Have you tried a different interval ? Like ->everyFiveMinutes()

OriOn left a reply on No Scheduled Commands Are Ready To Run | Empty

It's very strange indeed. Have you tried using composer dump-autoload to re-generate the list of all classes in your project?

OriOn left a reply on No Scheduled Commands Are Ready To Run | Empty

what about a \ at the begining of the string?

protected function schedule(Schedule $schedule)
{
    $schedule->command('\App\Console\Commands\HelpCenter')->everyMinute();
}

or try to replace the string with the command's signature as you did for your second example (Artisan::call('elena:help');)

OriOn left a reply on No Scheduled Commands Are Ready To Run | Empty

Is the command working at all? (if you run it via php artisan and the command's signature)

if so, what is the approximate execution time?

and is the storage/logs/laravel.log giving any clues where this could come from?

OriOn left a reply on Laravel Works With Non Existing Database

Hello, Is the config/database.phpfile also reading the .env file?

...
'default' => env('DB_CONNECTION', 'mysql'),
... 
'connections' => [
            'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',
        ],
...

OriOn left a reply on Mysql Connection Problems

phpunit.xml file is defining the testing environment.

have a look to mine I just changed a few lines from the original

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>

        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>
        <env name="MAIL_DRIVER" value="log"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>
</phpunit>

I change the DB_CONNCECTION and DB_DATABASE values for testing so it won't help you much if you insist on doing your tests in your actual database.

OriOn left a reply on Ajax Call To Get The Value Selected From A HTML Select Option

Hello,

I would use axios for this:

<select name="languageSelected" required="required" id="languageselector" onChange='showSelected(this.value)'>
    <option value="">Pick A language</option>
    @foreach($reviewForm_language as $lang)
        <option value="{{$lang->id}}">{{$lang->name}}</option>
    @endforeach
</select>
<button type="button" onclick="updateLanguage()">Select</button>

<div id="divId">
    {{-- where the content will be loaded --}}
</div>


<script type="text/javascript">
    function updateLanguage() {
        let languageselector = document.getElementById('languageselector').value;
        let url = {{ url('#') }};

        axios.get(url)
            .then(function (response) {
                let data = response.data;
                // to place in the div identified before 
                document.getElementById("divId").innerHTML = data;
            }).catch(function (error) {
                console.log(`Something went wrong!\n${error}`);
            });

    }
</script>

OriOn left a reply on One Confusing Thing About Gates And Policies

Every method inside a Policy should have its own name (its a php class).

You are not limited in the names

As an example I have a model called Action and in ActionPolicy I have

class ActionPolicy
{
    use HandlesAuthorization;

    public function create(User $user) { ... }
    public function beOwner(User $user, Action $action) { ... }
}

then later in the route/web.php

I use them via the middleware option

Route::middleware('can:create,App\Action')->group(function() { ... });

Route::middleware('can:beOwner,action')->group(function () {
    Route::get('action/{action}/edit', '[email protected]')->name('owner.edit');
}

OriOn left a reply on Is There An Alternative And More Efficient Method That Loop Through A Collection?

My bad I meant to test the number of reviews before the second loop

if ($event->reviews->count()) { ...

OriOn left a reply on One Confusing Thing About Gates And Policies

I happen to have several rules for a same "point" but it doesn't make it redundant either.

because different users have different "roles" the rules only lock down their own authorizations