OriOn

OriOn

Member Since 1 Year Ago

Experience Points 28,150
Experience Level 6

1,850 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 236
Lessons
Completed
Best Reply Awards 7
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

15 Mar
2 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

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 do that in your UserFactory->state()

14 Mar
2 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
2 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

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

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.

10 Mar
2 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.

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

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
2 months ago

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

24 Feb
3 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
3 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);
18 Feb
3 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
3 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
3 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
3 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 might do php artisan config:clear instead of cache:clear for the xml file edition.

11 Feb
3 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
3 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

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

for a single authorization "rule" you can define either a Gate or a Policy (it's only if you define both for a single ability that it becomes redundant)

the choice between one or the other only defines where the rule will be stored in your code. For Laravel it will be the same thing in the end because in the AuthServiceProvider.php your will "register" the policies:

public function boot()
    {
        $this->registerPolicies();

        //
    }

Laravel provides the Policies to improve code readability if your app contains a lot of authorization gates then you will get lost in the AuthServiceProvider.php file.

Policies allows you to store all authorization rules by category (the model)

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

If I understand well, the if shouldn't be in the foreach:

    foreach ($author->events as $event) {
        if ($review->ratings->count() > 0) {
       $a = [];
            foreach ($event->reviews as $review) {
                // if($review->rating == 0) { $stars = 0; }
                // elseif($review->rating == 1) { $stars = 20; }
                // elseif ($review->rating == 2) { $stars =40;}
                // elseif ($review->rating == 3) { $stars =60;}
                // elseif ($review->rating == 4) { $stars =80;}
                // else { $stars = 100;}      
                // $review['stars'] = $stars;
        // don't really need all of that I think
                $a[] = $review->rating * 20;
            }
            $event['avrRating'] = array_sum($a)/count($a);
        } else {
            $event['avrRating'] = 0;
        }
    }

OriOn left a reply on Mysql Connection Problems

Testing often use other storage so have a look into the phpunit.xml file to verify the settings. Some refer to values in your .env file as well.

04 Dec
5 months ago

OriOn left a reply on Define Relations Only By Orm ?

Hello, Eloquent "only" cares about the relationship within a model. I quote only because it might get problematic if on a database level things are different than in the models.

In the case of polymorphic relations, database level isn't achievable because the id should match one of the many related table so you can only implement these relation through models. (as far as I know..)

05 Nov
6 months ago

OriOn left a reply on Not Updating After Submitting To DB

@tykus you are faster than me =)

OriOn left a reply on Not Updating After Submitting To DB

Your unique validation isn't complete You are only specifying the table while the column needs to be specified as second argument and exception as third.

it would look like

'email' => 'required|email|unique:users,email,' . $user->id,

OriOn left a reply on Not Updating After Submitting To DB

Hello, you might want to review the edit method of your controller. the first command is overwriting the user binded from the route with the authenticated one: you are always displaying the edition form of the authenticated user, not the one aimed by the url.

simply remove the line

public function edit(User $user)
    {
     //   $user = Auth::user();
        return view('users.edit', compact('user'));
    }
08 Sep
8 months ago

OriOn left a reply on Laravel 5.7 Dusk Login Testing Fails With Wrong Credentials

You are using DatabaseMigrations so tables are migrated at the beginning of the test sequence and rolledback afterwards. remove the

use DatabaseMigrations;

if you want to observe the records yourself.

or you can add an assertDatabaseHas('users', .. to validate that the proper creation of the user via the factory within the test and before the browse would be ideal since you would know for sure it's there before attempting login

OriOn left a reply on Validate Rules When You Want To Edit Post?

Hello,

It would look the same as the one you posted in your message, at one exception.

The title validation would fail, you will have to add the (except parameter to the validation rule)[https://laravel.com/docs/5.7/validation#rule-unique]

$this->validate($request->all(), [
    'title' => 'required|max:190|unique:posts,title,{$post->id}',
    'description' => 'required',
    'poster' => 'required|image|max:51200'
]);

that means check that the title is unique in the posts table excepted for the id that you are updating.

OriOn left a reply on Laravel 5.7 Dusk Login Testing Fails With Wrong Credentials

Hello, the default UserFactory's password is the result of the 'old' encryption.

If your form is encrypting according to your 'new' encryption, it is to be expected that the assertion fails no?

07 Sep
8 months ago

OriOn left a reply on How To Turn Off Auto Login Users ? In Laravel 5.7

I did mention where this was happening in the vendor dealing with user registration.

just out of curiosity, may I ask why you want to do this?