james2doyle

james2doyle

at WARPAINT Media

Member Since 3 Years Ago

Experience Points 44,060
Experience
Level
Lessons Completed 435
Lessons
Completed
Best Reply Awards 0
Best Answer
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.

10 Aug
4 months ago

james2doyle left a reply on How To Test Symfony Process Inside A Queued Job?

I ended up using the service container as an alias and then replace that in the test.

So I would have this in the AppServiceProvider:

// Alias App\Process to the Symfony Process so we can mock in tests
$this->app->bind('App\Process', function ($app, $args) {
     return new \Symfony\Component\Process\Process(...$args);
});

Then in my command I had a line like the following instead of doing the "getProcess" method:

$process = app('App\Process', [$cwd]);

Finally, I can update my test to be like so:

$process = Mockery::mock('Symfony\Component\Process\Process');
$process->shouldReceive(
    'setTimeout',
    'run',
    'wait',
    'stop',
    'getCommandLine',
    'getExitCode',
    'getExitCodeText',
    'getWorkingDirectory',
    'isOutputDisabled',
    'getErrorOutput'
);

$process->shouldReceive('isSuccessful')->andReturn(true);
$process->shouldReceive('getOutput')->andReturn('sent for execution');

// replace the instance of the Symfony Process with our mock
$app->bind('App\Process', function ($app, $args) use ($process) {
    return $process;
});

$this->expectOutputString('sent for execution');
$this->artisan('mycommand');

As you can see the test contains all the mock stuff now instead of the actual command.

02 Jun
1 year ago

james2doyle left a reply on Best Way To Test Event Listeners

Here is how I tested that an event listener was called without any additional frameworks:

$this->app->resolving(function ($object, $app) {
    // Called when container resolves object of any type...
    if ($object instanceof MyEventListener) {
        $this->assertTrue(true, MyEventListener::class . ' was not called.');
    }
});

This is very crude as it looks at all the objects being resolved in the application . It is also extremely slow.

10 Mar
1 year ago

james2doyle left a reply on Upload Errors When Laravel App Online

I was having this issue with Laravel 5.4. I fixed by setting post_max_size and upload_max_filesize in my php.ini to a higher value.

After that, I actually had to do a hard restart of OSX before it would actually reflect in the application properly and it would stop sending the incorrect mime type.

23 Mar
2 years ago

james2doyle left a reply on Php Artisan Error

I was getting this error when just running php artisan.

I checked my log and saw there was a problem accessing an object in one of my Service Providers. Turns out there was a cached item that was expecting an object but was returning null. So it was throwing an Exception.

I updated the code to catch and handle the exception and then everything was OK!

04 Feb
2 years ago

james2doyle left a reply on Laravel 5 Validation Request, How To Handle Validation On Update?

I know this is sort of old now. But I encountered this when updating a user profile in the default Laravel Auth setup. I have a Form Request called "UserUpdateRequest", and I got the form to submit, with the same email, by using the following setup:

I have a method in my resource controller like this:

// route method is PUT, route looks like /users/1
public function update(UserUpdateRequest $request, $id)
    {
        // ... update user with $request->all();
    }
public function rules()
    {
        return [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users,email,'.$this->users,
        ];
    }

This is strange because $this->users contains the ID of the submission, some posts in here say to use $this->id, but that didn't seem to work for me.

29 Jan
2 years ago

james2doyle left a reply on Sub Domain Routing Without Closures

I ended up going with something similar:

For the routing I use this:

Route::group([
   'middleware' => ['web'],
   'domain' => '{domain}.strideapp.local'], function () {
   // how do I avoid a closure here, but still include {domain}?
   Route::get('/{slug?}', 'FrontendController@serve')->name('serve');
});
// FrontendController.php
// ...
public function serve(Request $request)
{
      $params = $request->route()->parameters();
      return view($params['domain'] . '.' . $params['slug']);
}
// ...

james2doyle started a new conversation Sub Domain Routing Without Closures

Hello, I'm trying to do some subdomain routing, but I don't want to have inline Route::method commands with callbacks/closures.

Is there a way to do this without that?

Route::group(['middleware' => ['web'], 'domain' => '{domain}.strideapp.local'], function () {
 // how do I avoid a closure here, but still include {domain}?
 Route::get('/{slug?}', 'FrontendController@serve')->name('serve');
});
05 Jun
3 years ago

james2doyle started a new conversation View Facade In Blade Extension

I am trying to use a Blade extension to render a View partial. This is my code so far:

Blade::extend(function($value, $compiler)
{
  $pattern = $compiler->createMatcher('navigation');
  $tree = Page::getTree();
  $template = View::make('Theme::decorators.nav-item')->with('pages', $tree)->render();
  return preg_replace($pattern, $template, $value);
});

The nav-item view is simply a nested UL list.

The problem is, using this trick, it seems to be causing my app to hang, my response goes empty.

I was previously just using a loop with a sprintf function, but using a view like this seems way nicer.

Does anyone have any experience doing this? Here are the things I have tried to far:

  • Using the View facade
  • Using the view() helper
  • Using a full path call to the View facade
27 Apr
3 years ago

james2doyle left a reply on Append A Blade @section Inside A Controller

Maybe a code example might help. Here is the gist of what I ended up doing:

<?php
$field_template = "";
foreach (Fields::getFields() as $field) {
    $field_template .= View::make($field->view_name)->with("data", $field->data)->render();
}
return View::make("controller.create")
->with("fields", $field_template)
->with("page", $page);

Now if you dumped the $field_template variable, you would find a string that had a bunch of blade templates concatenated inside of it, filled with normal blade stuff like loops, sections, parent references, etc.

I did this because I had no idea how many Field results are going to be returned. Using nest wouldn't have worked well for this, as far as I understand.

The alternative to this solution would have been to send the information to the view in an array, then loop over each Field in blade, doing an @include for each view.

26 Apr
3 years ago

james2doyle left a reply on Append A Blade @section Inside A Controller

Ok so I have found a solution. I figured it was a long shot, but it works!

It seems like blade code gets parsed at the end of the last View::make call. This means I can use @parent and @section in a different blade view, call render() on that view, and even though I am dumping a string into my main layout, the blade @section/parent still get parsed.

This means you can just dump a string that contains blade syntax into a view, and then view will still treat the field the same. A blade view will get parsed once it is fully built. Which means there is no difference between including a string with blade in it, and typing out the blade in the view.

I thought, that maybe it was being parsed in sections but I guess that is not the case.

james2doyle left a reply on Append A Blade @section Inside A Controller

Thanks @umefarooq I might just have to build up a string like that and dump it in.

Also thanks @pmall. Nest is documented in the L5 API docs. I saw it there but I wasn't sure if it would work for me.

25 Apr
3 years ago

james2doyle started a new conversation Append A Blade @section Inside A Controller

I have been trying to figure out the best way to do this without using some hacky string-replace stuff. I want to be able to append content to a section in my view. But, I want to do this in my controller.

Here is some pseudo code for what I am looking to do:

return View::make('Page::create')
        ->section('styles', $stylesheet_tag) // something like this
        ->with('page', $page);

Is this possible? I haven't found any methods that would facilitate this kind of functionality.

More information: I am generating a view that has a dynamic form. I can append fields as I need them based on the settings for the form. This works great. But, once I start requiring additional javascript or CSS for these dynamic fields, I need to be able to properly append these to the @yield("styles") and @yield("scripts") sections in my layout.

Can I do this inside a controller or do I need to break out this additional fields into their own blade @include sections?

24 Apr
3 years ago

james2doyle left a reply on Ho To Access Config Variables In Laravel 5?

In /config/app.php you can add a line like so:

'theme_path' => __DIR__.'/../resources/views/theme',

Then in any model/controller/etc. you can access that value via config('app.theme_path') or Config::get('app.theme_path').

If you want to use Config::get('app.theme_path'), make sure you include the Config facade.