smnhunt

smnhunt

Member Since 4 Years Ago

Experience Points 36,630
Experience Level 8

3,370 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 431
Lessons
Completed
Best Reply Awards 2
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.

01 Mar
1 month ago

smnhunt left a reply on Extending Package Model To Your Own

Looking at that with fresh eyes, I can see that it wouldn't be that.

Have you created the migration and migrated your database already?

28 Feb
1 month ago

smnhunt left a reply on Extending Package Model To Your Own

I notice that the InboundEmail class has a boot() method in it, which in turn calls its parent::boot() method.

Do you need to include:

protected static function boot()
    {
        parent::boot();
    }

in your Email class?

14 Jan
3 months ago

smnhunt left a reply on Change The Format Of A Date Before Saving?

Are you casting the field to a date in the $dates array of your model?

11 Jan
3 months ago

smnhunt left a reply on Data Not Displaying On The Browser

I meant what does this actually display in the console? Copy and paste it in so that I can see.

smnhunt left a reply on Data Not Displaying On The Browser

What is the output from console.log(data) in your async call?

10 Jan
3 months ago

smnhunt left a reply on Permissions On Model

You could have a permissions JSON field on the Post model that contains a JSON array. This would localise post specific permissions within the post model, rather than have the requirements spill over into the rest of your app.

The array could look something like:

{
    "permissions": [
        "editor": [
            'user_id_1', 'user_id_2'
        ],
        "owner": [
            'user_id_3, 'user_id_4'
        ]
    ],
}

etc.

This article has more information about JSON features that were introduced in Laravel 5.3: https://themsaid.com/laravel-mysql-json-colum-fast-lookup-20160709

smnhunt left a reply on Form Model Binding In 5.7

Thanks @zion hadn't spotted that.

So now just:

value="{{ $user->firstname ?? old(firstname) }}"

smnhunt left a reply on Form Model Binding In 5.7

Alternatively, this can be done without the need for a blank model using the blade or operator:

https://laravel-news.com/blade-or-operator

This would make your value attribute look something like this:

value="{{ $user->firstname or old(firstname) }}"

Which will compile to:

isset($user->firstname) ? $user->firstname : old(firstname)

smnhunt left a reply on Why Isn't Data Updating?

Is it because you are directly manipulating an array?

https://vuejs.org/2016/02/06/common-gotchas/

07 Jan
3 months ago
20 Mar
1 year ago

smnhunt left a reply on Dusk Test Does Not See Database Update

I'm having this problem too. The pause does the trick, but I can't help wondering if there is a better way?

The reason I say this is because I've just transferred a test suite from a fast Linux machine to a 2012 iMac and had to edit all of my tests to account for the fact that it is slower. My Linux box was cruising with delays of 25 ms but the iMac needs closer to 100 ms.

Maybe I should be waiting for an element (eg. an alert that tells the user that their request has been successful) rather than just a set amount of time.

13 Nov
1 year ago

smnhunt left a reply on Useful Routing In Laravel

I'd definitely suggest watching this: https://www.youtube.com/watch?v=MF0jFKvS4SI

11 Oct
1 year ago

smnhunt left a reply on Generating CSS From From SASS Based On Variables Values From Database

I'm not sure this is possible in this way.

Could you retrieve your values from the database (perhaps in a view composer) and then inject them into your html as JSON? (I believe Laravel 5.5 blade now has a @json() directive for this very purpose)

You could then write some javascript that updates the values of the css variables from the JSON data on the client side.

06 Oct
1 year ago

smnhunt left a reply on Since Laravel Mix PhpStorm Become Slow When Watch Is Running

I've had problems with the Mix watch command the last few days as well (see this issue: https://github.com/JeffreyWay/laravel-mix/issues/1230).

It won't run at all when I'm using VS Code - though I haven't noticed a performance issue with PHP Storm yet.

Having explored I've noticed similar problems when I try to run BrowserSync independently (again with VS Code but not PHP Storm).

30 Sep
1 year ago

smnhunt left a reply on Laravel Mix - Vendor Files Only Required By Some Pages

This might be too simple for what you are trying to do but would the following work:

Create a new javascript file pageSpecific.js.

Pull out the libraries that you only want to be included in pageSpecific.js from app.js.

window.Vue = require('vue');
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

let token = document.head.querySelector('meta[name="csrf-token"]');

if (token) {
    window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}

Now modify the webpack.mix.js file:

mix.js('resources/assets/js/app.js', 'public/js')
   .js('resources/assets/js/pageSpecific.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

and recompile.

Now include (or not) in your templates:

<script src="/js/app.js"></script>
<script src="/js/pageSpecific.js"></script>

This may not play nicely with the cache busting file versioning feature. However, if reducing file size is your main concern it would work.

Also, if you then find that you are including the same dependencies in all of your page specific files, you could extract those includes into a separate vendor.js file and just include this where necessary too.

It's basically just manual extraction.

28 Sep
1 year ago

smnhunt left a reply on Laravel Mix - Vendor Files Only Required By Some Pages

It feels like their might be a pull request in here somewhere!

smnhunt left a reply on Laravel Mix - Vendor Files Only Required By Some Pages

Ahhh, I see. Sorry - I missed the point of the original question and didn't mean to patronise.

Looking at the docs it doesn't look like extract() was designed with this use case in mind.

smnhunt left a reply on Laravel Mix - Vendor Files Only Required By Some Pages

Whenever I want to put different Javascript on different pages I use blade stacks to achieve this.

In your view template:

@push('scripts')
    <script src="/js/appSearch.js"></script>
@endpush

And then in your main html template:

<head>
    <!-- Head Contents -->

    @stack('scripts')
</head>

I quite often have one stack called bodyScripts (which I output just above the closing body tag) and one called headScripts (which goes in the head section).

22 Sep
1 year ago

smnhunt left a reply on TokenMismatchException In VerifyCsrfToken.php (line 68)

If your are placing {{ csrf_token() }} inside your form, you should instead try {{ csrf_field() }}.

csrf_token() returns the value of the token.

csrf_field() returns the html for a hidden input that passes the value of the csrf_token() to your app.

smnhunt left a reply on Using Route::get() After Route::resource()

Try removing the $ signs:

Route::get('admin/{user}/tasks/{task}', '[email protected]')

Also, I think you need to define this rule before you define your resource route.

smnhunt left a reply on Composer Install Package With Dev Dependencies

From my experience:

composer install

installs dev dependencies by default.

I've always had to run:

composer install --no-dev

to not install them.

05 Feb
2 years ago

smnhunt left a reply on Valet 2.0 – 502 Bad Gateway

I was getting this error. I fixed it by reinstalling php-fpm and then reinstalling valet.

25 Dec
2 years ago

smnhunt started a new conversation Is Anyone Using Behat 3, Laravel 5 And Zombie.js 4?

I'm trying to get a Behat environment setup within Laravel which is able to test a Laravel application with javascript.

I've landed on zombie.js as a virtual browser which seems fast.

It works perfectly for all simple browser tests (including javascript) but fails as soon as I test anything which requires authentication. Any pages behind authentication return as though the user us a guest (usually a 403 error).

Is anyone else using this setup? Has anybody else had this problem? Can anyone help?

03 Aug
2 years ago

smnhunt started a new conversation Alias Failing When Object Passed (Bug?)

I have the following code:

// Departments
        $physics = factory(App\Base\Academy\Department::class, 1)->create();
        $chemistry = factory(App\Base\Academy\Department::class, 1)->create();
        $biology = factory(App\Base\Academy\Department::class, 1)->create();

        // Subjects
        $subject_chemistry = factory(App\Base\Qualification\Subject::class, 1)->create([
            'name' => 'Chemistry',
        ]);
        $subject_biology = factory(App\Base\Qualification\Subject::class, 1)->create([
            'name' => 'Biology',
        ]);
        $subject_physics = factory(App\Base\Qualification\Subject::class, 1)->create([
            'name' => 'Physics',
        ]);

        // Attach
        $chemistry->attachToSubject($subject_chemistry);
        $biology->attachToSubject($subject_biology);
        $physics->attachToSubject($subject_physics);

Which is returning the following error:

PHPUnit 4.8.27 by Sebastian Bergmann and contributors.

.E.........................................

Time: 1.29 seconds, Memory: 26.00MB

There was 1 error:

1) DashboardTest::a_school_admin_sees_the_school_admin_section_on_the_dashboard
TypeError: Argument 1 passed to App\Base\Academy\Department::attachToSubject() must be an instance of Subject, instance of App\Base\Qualification\Subject given, called in /home/simon/Code/cpactracker.co.uk/tests/Acceptance/DashboardTest.php on line 69

/home/simon/Code/cpactracker.co.uk/app/Base/Academy/Department.php:51
/home/simon/Code/cpactracker.co.uk/tests/Acceptance/DashboardTest.php:69
/home/simon/Code/cpactracker.co.uk/tests/Acceptance/DashboardTest.php:35

So it would appear that their is an error in the use statement of the Department class.

use Subject;

Which I have set as an alias elsewhere.

So if I change it to:

use App\Base\Qualification\Subject;

It works, but I lose the ease of using the alias.

However, if I change just one of the code blocks where the subjects are defined like so:

        $subject_chemistry = factory(App\Base\Qualification\Subject::class, 1)->create([
            'name' => 'Chemistry',
        ]);
        $subject_biology = factory(App\Base\Qualification\Subject::class, 1)->create([
            'name' => 'Biology',
        ]);
        $subject_physics = Subject::create([
            'name' => 'Physics',
        ]);

(notice to the change to the last block).

It works even without changing the alias. It makes not difference what order the subject definitions are in, as long as one of them uses Subject::create, even if the other two still use model factories.

I'm baffled by this.

smnhunt left a reply on Problem With AssertRedirectedToRoute()

GET|HEAD  | school/{school}/teacher                             | school.{school}.teacher.index   | App\Http\Controllers\[email protected]                      | web        

It's not a routing issue. I've run into the problem again, multiple times throughout my work.

Just can't quite seem to get it fixed.

I've resorted to using the seePageIs() function instead which seems to work fine.

01 Aug
2 years ago

smnhunt started a new conversation Problem With Redirects

Hi,

I'm probably making a daft mistake but just don't seem to be able to get assertRedirectToRoute() to work in my tests - any help would be gratefully appreciated.

I have a controller function which returns a view with a form:

    public function create(School $school)
    {
        return view('form.create-teacher', [
            'school' => $school,
        ]);
    }

And the form action direct to this function:

    public function store(Request $request, School $school)
    {
        $this->validate($request, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
        ]);

        $user = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'password' => $request->password,
        ]);

        $teacher = Teacher::create();
        $teacher->attachToUser($user);
        $teacher->attachToSchool($school);

        return \Redirect::route('school.{school}.teacher.index', ['school' => $school->id]);
    }

The test that I am running is as follows:

    public function a_school_admin_can_add_a_teacher_to_their_school()
    {
        // Given: A school exists and I visit the create teacher page.
        $school = factory(App\Base\Academy\School::class, 1)->create();
        $this->visit('school/1/teacher/create');

        // When: The teacher is registered.
        $this->type('Mr Smith', 'name')
             ->type('[email protected]', 'email')
             ->type('password', 'password')
             ->type('password', 'password_confirmation')
             ->press('Register');

        // Then: The changes are reflected in the database.
        $this->seeInDatabase('users', ['name' => 'Simon Hunt']);
        $this->seeInDatabase('teachers', ['user_id' => 1, 'school_id' => 1]);
        $this->assertRedirectedToRoute('school.{school}.teacher.index', ['school' => 1]);
    }

And the error that I am receiving is as follows:

PHPUnit 4.8.27 by Sebastian Bergmann and contributors.

.F

Time: 179 ms, Memory: 16.00MB

There was 1 failure:

1) SchoolAdminTest::a_school_admin_can_add_a_teacher_to_their_school
Failed asserting that Illuminate\Http\Response Object (...) is an instance of class "Illuminate\Http\RedirectResponse".

/home/simon/Code/cpactracker.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:724
/home/simon/Code/cpactracker.co.uk/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:743
/home/simon/Code/cpactracker.co.uk/tests/Acceptance/SchoolAdmin/SchoolAdminTest.php:54

FAILURES!
Tests: 2, Assertions: 10, Failures: 1.

It seems as though all other parts of the test are working except for the assertRedirectedToRoute part.

17 Jul
2 years ago

smnhunt left a reply on Different Database In Different Tests - Is It Possible?

Where do you think would be the best place to do this? In the test setUp() method?

smnhunt started a new conversation Different Database In Different Tests - Is It Possible?

I know that it is possible to setup a separate database for testing and local.

I have been using an in memory sqlite database to test my models/repositories and seeders but would now like to work with a live database to test my api.

Is it possible to have different tests use different databases? Perhaps there is a property that can be overridden on a test by test basis?