0 Best Reply Awards

  • Member Since 3 Years Ago
  • 429 Lessons Completed
  • 1 Favorite

10th August, 2018

james2doyle left a reply on How To Test Symfony Process Inside A Queued Job? • 2 months ago

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('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');

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

2nd June, 2017

james2doyle left a reply on Best Way To Test Event Listeners • 1 year ago

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.

10th March, 2017

james2doyle left a reply on Upload Errors When Laravel App Online • 1 year ago

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.

23rd March, 2016

james2doyle left a reply on Php Artisan Error • 2 years ago

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!

4th February, 2016

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

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.

29th January, 2016

james2doyle left a reply on Sub Domain Routing Without Closures • 2 years ago

I ended up going with something similar:

For the routing I use this:

   '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 • 2 years ago

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');

5th June, 2015

james2doyle started a new conversation View Facade In Blade Extension • 3 years ago

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

27th April, 2015

james2doyle left a reply on Append A Blade @section Inside A Controller • 3 years ago

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

$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.

26th April, 2015

james2doyle left a reply on Append A Blade @section Inside A Controller • 3 years ago

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 • 3 years ago

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.

25th April, 2015

james2doyle started a new conversation Append A Blade @section Inside A Controller • 3 years ago

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?

24th April, 2015

james2doyle left a reply on Ho To Access Config Variables In Laravel 5? • 3 years ago

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.

Edit Your Profile

Want to change your profile photo? We pull from gravatar.com.