phildawson

phildawson

Member Since 4 Years Ago

Oxford, UK

Experience Points 125,050
Experience Level 26

4,950 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 135
Lessons
Completed
Best Reply Awards 149
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.

06 Oct
3 years ago

phildawson left a reply on Model HasManyThroughMany Relationships

@rleger I've just updated the post above. Would that work?

phildawson left a reply on Model HasManyThroughMany Relationships

I can see this ties the diagnostics to the patient but doesn't separate what diagnostic was on what intervention.

phildawson left a reply on Model HasManyThroughMany Relationships

I'm just trying to see the structure at the moment based of this relationship you spoke of

Intervention hasMany Patient
Patient belongsTo Intervention
Patient hasMany Diagnostic
Diagnostic belongsTo Patient
interventions
id 

patients
id intervention_id

diagnostics
id patient_id
class Intervention
{
    function patients()
    {
        return $this->hasMany(Patient::class);
    }
}

class Patient
{
    function intervention()
    {
        return $this->belongsTo(Intervention::class);
    }

    function diagnostics()
    {
        return $this->hasMany(Diagnostic::class);
    }
}

class Diagnostic
{
    function patient()
    {
        return $this->belongsTo(Patient::class);
    }
}
05 Oct
3 years ago

phildawson left a reply on Can't Play Videos On Firefox

Try this, it should be much clearer.

https://www.youtube.com/html5

phildawson left a reply on Set Custom Header For Any Response

@raphael as @pmall has mentioned this is all responses.

If you wanted to narrow it down to just responses formed from views then you'll need to obviously check before slapping the header on everything.

    public function handle($request, Closure $next)
    {
        $response = $next($request);

        if ($response instanceof Response and $response->original instanceof View)
        {
           $response->header('Cache-Control', 'no-cache, must-revalidate');
        }
        
        return $response;
    }

phildawson left a reply on Set Custom Header For Any Response

Yeah it's super easy.

  1. Open \App\Http\Kernel.php

add to $middleware

 \App\Http\Middleware\NoCache::class,
  1. create the file \App\Http\Middleware\NoCache.php
<?php

namespace App\Http\Middleware;

use Closure;

class NoCache
{
    public function handle($request, Closure $next)
    {
        $response = $next($request);

        $response->header('Cache-Control', 'no-cache, must-revalidate');

        return $response;
    }
}

Done.

phildawson left a reply on Can't Play Videos On Firefox

If you go to vimeo.com can you play any videos?

phildawson left a reply on Missing Model::find() Method? Or Just Me

This should be the same

laravel new test && cd test
cp .env.example .env
php artisan key:generate
echo "DB_CONNECTION=sqlite" >> .env
touch database/database.sqlite
php artisan migrate
php artisan tinker
factory(App\User::class,3)->create();
App\User::find(2);

phildawson left a reply on Missing Model::find() Method? Or Just Me

So does that work for you Istables? Kinda lol @ "Randal Batz III"

phildawson left a reply on Missing Model::find() Method? Or Just Me

composer create-project laravel/laravel test --prefer-dist
cd test
echo "DB_CONNECTION=sqlite" >> .env
touch storage/database.sqlite
php artisan migrate
php artisan tinker
factory(App\User::class,3)->create();
=> Illuminate\Database\Eloquent\Collection {#701
     all: [
       App\User {#712
         name: "Randal Batz III",
         email: "dawn.beier@hotmail.com",
         updated_at: "2015-10-05 10:35:35",
         created_at: "2015-10-05 10:35:35",
         id: 1,
       },
       App\User {#713
         name: "Malika Conn",
         email: "hcorwin@jones.org",
         updated_at: "2015-10-05 10:35:35",
         created_at: "2015-10-05 10:35:35",
         id: 2,
       },
       App\User {#700
         name: "Keara Cormier",
         email: "eva.bahringer@hotmail.com",
         updated_at: "2015-10-05 10:35:35",
         created_at: "2015-10-05 10:35:35",
         id: 3,
       },
     ],
   }
App\User::find(2);
=> App\User {#719
     id: "2",
     name: "Malika Conn",
     email: "hcorwin@jones.org",
     created_at: "2015-10-05 10:35:35",
     updated_at: "2015-10-05 10:35:35",
   }

phildawson left a reply on Why I Cannot Show My Laravel Project In Free Hosting?

They are running unsupported PHP versions and in PHP5.4 class name resolution doesn't exist.

02 Oct
3 years ago

phildawson left a reply on Laravel 5 Mandrill Guzzle Custom Curl Options

So I would

  1. config/app.php

// Illuminate\Mail\MailServiceProvider::class,

and add your own App\Providers\CustomMailServiceProvider::class,

  1. Make that CustomMailServiceProvider.php it'll be something like
<?php

namespace App\Providers;

use App\CustomTransportManager;
use Illuminate\Mail\MailServiceProvider;

class CustomMailServiceProvider extends MailServiceProvider
{
    protected function registerSwiftTransport()
    {
        $this->app['swift.transport'] = $this->app->share(function ($app) {
            return new CustomTransportManager($app);
        });
    }
}
  1. Then create that CustomTransportManager.php in app
<?php

namespace App;

use Illuminate\Mail\TransportManager;

class CustomTransportManager extends TransportManager
{
    protected function createMandrillDriver()
    {
        $client = new HttpClient([
                'curl' => [CURLOPT_INTERFACE => '1.2.3.4']
        ]);

        $config = $this->app['config']->get('services.mandrill', []);

        return new MandrillTransport($client, $config['secret']);
    }
}

phildawson left a reply on PHPUnit V5 Is Out

5.3!! Ouch, what have you done to deserve that? Isn't L4.2 needing PHP >= 5.4?

phildawson left a reply on Laravel 5 Mandrill Guzzle Custom Curl Options

Yeah sorry I should have been clear, the binding won't work. The example above placed in the routes.php does work but thats because the dependency in the Example construct is being resolved out of the container, which the binding returns the config'd class.

The issue is in the TransportManager class it isn't injected but new'd up directly inside the method.

 protected function createMandrillDriver()
    {
        $client = new HttpClient;

    ...

phildawson left a reply on Project Not Working On Subdirectory.

Yeah is really not worth giving yourself a headache to work around shit hosting setups. Hosts should be working to how you want to work not the other way round.

Drop them pick fortrabbit/ Digitalocean, something that gives you full SSH and control over server config, and the up-to-date software. Laravel can work anywhere but its designed for the files to be behind the publicly accessible.

/var/www/project.domain.com/public

Get yourself a domain for a couple of quid and set each project as a subdomain would be my advice.

phildawson left a reply on PHPUnit V5 Is Out

Probably a good thing 5.5 has been unsupported for quite some time. A good decision to push things forward, and I mean PHP7 out in the next few weeks too :) .. Oct 15 2015 (RC 5) Oct 29 2015 (RC 6) Nov 12 2015 (Final)

phildawson left a reply on Laravel 5 Mandrill Guzzle Custom Curl Options

Mm good question as it's not resolved out the container you can't do this

<?php

class Example
{
    function __construct(GuzzleHttp\Client $client)
    {
        $this->client = $client;
    }

    function example()
    {
        $this->client->request('GET', 'http://laravel.com');
    }
}

$this->app->bind(GuzzleHttp\Client::class, function()
{
    return new GuzzleHttp\Client([
        'curl' => [
            CURLOPT_INTERFACE => '1.2.3.4'
        ]
    ]);
});

get('/', function(){

    app(Example::class)->example();

    exit;
});

phildawson left a reply on Laravel 5 Mandrill Guzzle Custom Curl Options

I would say you need to switchout Illuminate\Mail\TransportManager for your own where the driver is created.

    protected function createMandrillDriver()
    {
        $client = new HttpClient;
    $client->getConfig('curl.options')->set(CURLOPT_INTERFACE, 'xxx.xxx.xxx.xxx');

        $config = $this->app['config']->get('services.mandrill', []);

        return new MandrillTransport($client, $config['secret']);
    }
01 Oct
3 years ago

phildawson left a reply on Forget An Observer

You can forget() to unset an event listener.

    Event::listen('a', function(){
        Event::forget('a');

        echo 'update a ';
        event("b");
    });

    Event::listen('b', function(){
        Event::forget('b');

        echo 'update b ';
        event("a");
    });

    event("a"); // update a update b

The models are named as "eloquent.{$event}: {$name}" eg "eloquent.updated: Foo"

phildawson left a reply on Get Information From A Foreign Key, When It Has Multiple Entries In A Table

So starting with the schema we have

users
id name

transactions 
id given_to received_from
class Transaction extends Model
{
    function givenTo()
    {
        return $this->belongsTo(User::class, 'given_to');
    }

    function receivedFrom()
    {
        return $this->belongsTo(User::class, 'received_from');
    }
}
class User extends Model
{

}
foreach($transactions as $transaction) {
    $transaction->givenTo->name;
}

phildawson left a reply on Getting Errors In Production Only

@Man

The relationship on the Model

class Post extends Model
{
    function similar()
    {
        ...
    }
}

The controller does the working out of what vars to pass to the view

class PostController extends Controller
{
    function view($id)
    {
        $post = Post::with('similar')->findOrFail($id);
        $foo = 'bar';

        return view('sidebar', compact('post', 'foo'));
    }
}

The views job is just using those params passed through


<h1><?= $foo; ?></h1>

<?php foreach($sidebar->similar as $post): ?>

<?php endforeach;

phildawson left a reply on Entities Tightly Coupled With Eloquent

Why feel weird about it? You don't have to use it, it's just a helpful way of getting the results in one swoop.

Actually when it tries to get the relationship after checking the key doesn't exist, it calls getResults on the Relation. For belongsTo it will actually do first() rather than get() which is nifty.

$user->book()->first()
$user->books()->get()

vs

$user->book
$user->books

Its much nicer without all that get first getting in the way of reading the relationship. All I want to see is user->book, this is the book of the user.

phildawson left a reply on Getting Errors In Production Only

@Man so the code and the database schema and content are indentical on local/production? I doubt it would be anything to do with the apache/nginx

So

posts
id category_id ...

categories
id ...
class Post extends Model
{
    function category()
    {
        return $this->belongsTo(Category::class);
    }
}

class Category extends Model
{
    function posts()
    {
        return $this->hasMany(Post::class);
    }
}
foreach($post->category->posts as $post) {
    
}

phildawson left a reply on Getting Errors In Production Only

So you are trying to find a post by another posts category_id?

$post_category = Post::find($post->post_category_id);

What happens if it can't find that? When it comes to getting the sidebar posts it will fail trying to get a property of a non-object

->where('post_category_id', '=', $post_category->id)

phildawson left a reply on Running Laravel On A Windows Server

i was thinking of creating a laravel project in a windows server and running an API from there.

Yeah fuck that I wouldn't run any websites on Windows Servers/Azure. If it needs to be kept on SQL Server (and can't be exported) then just have the database running on it and put the host in the sqlsrv config to connect to it.

phildawson left a reply on Calling All Freelance Laravel Developers - Pays In Bitcoin

@rjmacarthy post here instead. https://larajobs.com/register?to=/jobs/create

Posting on the help forums is likely to get your account disabled.

phildawson left a reply on File Issues/complications

I only use forge but I would suggest keeping the actual storage out of that folder. I have a site that does this for the deploy script

cd /home/forge/default
git pull origin master

rm -rf /home/forge/default/storage/files
ln -s /home/forge/s3/files /home/forge/default/storage/files

composer install --no-interaction --no-dev --prefer-dist
php artisan migrate --force
30 Sep
3 years ago

phildawson left a reply on My Website Is Too Slow...

It's the server rather than your code. Try just a single resource which should be instant but takes like 20 seconds

http://minghan.sg/js/bundle.js

phildawson left a reply on My Website Is Too Slow...

I've just tried to visit http://minghan.sg/ and it's taken ~5 minutes before it gave up!

phildawson left a reply on My Website Is Too Slow...

Care to share the url?

phildawson left a reply on Can I Use PHP 5.5.29 With Laravel 5.1

Huh L5.1 requires PHP >= 5.5.9 and you have 5.5.29 so that's fine.

phildawson left a reply on [L5] Model::create Except Certain Fields

Yes. You can either as separate params

except('referee_name', 'referee_email','etc')

or pass as array

except(['referee_name', 'referee_email','etc'])

The $fillables on the model controls what gets filled so if 'referee_name' isn't in the array it will ignore it.

However if 'referee_name' is in your $fillables but for a specific case don't want that key from the request then do this.

phildawson left a reply on [L5] Model::create Except Certain Fields

Applications::create($request->except('referee_name'));

phildawson left a reply on How To Create Year Datatype (mysql) From Eloquent

Or use the DB statement

ALTER TABLE `cars ` ADD `year` YEAR NOT NULL
29 Sep
3 years ago

phildawson left a reply on Laravel 5.1 The Last() Method Not Working

Project::where('user_id', auth()->id())->oldest()->first();

phildawson left a reply on Eager Loading All Relationships

No as it's not really going to be a common thing, as it'll be wasting queries rather than saving them.

It would be fairly easy though using reflection to test all the methods for a return instance of Relation and set the $with automatically.

phildawson left a reply on How To Sync Data On Pivot Table With Where Clause?

It feels like it should be this

$page->tags()->wherePivot('feature_id', 1)->sync($tagIds);

phildawson left a reply on Noob Question -> Config Dir

Yeah it's best to keep secure bits out of the repo. If you are working by yourself then there's no fuss.

I think it's just to save the weight of the default .env file being filled with things people rarely config.

If you need say FTP details then its up to the person to add them and modify

FTP_USERNAME=foo
FTP_PASSWORD=bar
'username' => env('FTP_USERNAME', 'your-username')
'password' => env('FTP_PASSWORD', 'your-password')

phildawson left a reply on Problem Creating A Laravel App With Command 'laravel New'

I have apparently found the solution here: I think the laravel command is an alias to the actual composer command to create a new project.

Nah it does something different. It downloads a zip with Guzzle, and extracts it. This is the command it runs https://github.com/laravel/installer/blob/master/src/NewCommand.php

I prefer composer over laravel new as it also sets the app key.

28 Sep
3 years ago

phildawson left a reply on Problem Creating A Laravel App With Command 'laravel New'

@souleye

do this in Terminal to check the current paths

echo $PATH

phildawson left a reply on Problem Creating A Laravel App With Command 'laravel New'

I think you missed this bit

Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable can be located by your system.

phildawson left a reply on Models & Objects

Then I'm doubting myself as to whether this is going to be referencing the right model and updating the correct user and then it's all downhill from there.

Yes it's all fine. $this is acting on the User object representing that user row. It's just affecting that.

class User extends Model
{
    function addReward($reward)
    {
        $this->points += $reward
    }
}

$user = User::find(1);
$user->addReward(10);
$user->save();

phildawson left a reply on Need Help With Model Binding

http://laravel.com/docs/5.0/routing#route-model-binding

Route::get('article/{article}', ...

Route::bind('article', function($value)
{
    return Article::where('title', $value)->first();
});

phildawson left a reply on Take The Name Of The Column Instead The Id

You would add the relationship on the 'Knowns'. Try and name your models singular though so Known.

users 
id, name

type_specialists 
id, name

knowns 
id, user_id, type_specialist_id, description
class User extends Model
{
    function knowns()
    {
        return $this->hasMany(Known::class);
    }
}

class Known extends Model
{
    function typeSpecialist()
    {
        return $this-> belongsTo(TypeSpecialist::class);
    }
}

class TypeSpecialist extends Model
{

}

phildawson left a reply on Should A Repo Only Work With It's Own 'entity'

@martinbean no worries, I thought it was odd with the time diff. The forums are rubbish on phone, especially with lack of timestamps. I think Jeff mentioned he's working on a whole new site for Laracasts which should hopefully fix the bad phone support.

phildawson left a reply on Should A Repo Only Work With It's Own 'entity'

@martinbean @luddinus wasn't this question posted a year ago? ;)

phildawson left a reply on URL With Trailing Slashes Gets Redirected To Localhost

uncomment

RewriteBase /rnd/public/

remove /

RewriteRule ^(.*)/$ $1 [L,R=301]

phildawson left a reply on Method Dependency In A Services Class

@jekinney @rbruhn

If you want method injection you can use call.

Going back to my previous example

<?php

$this->app->bind(App\Repositories\Contracts\Project::class, App\Repositories\Project::class);

get('/', function(){

    $result = app()->call([new App\Services\ProjectService, 'show'], [4]);

    dd($result);

});
<?php

namespace App\Services;

use App\Repositories\Contracts\Project;

class ProjectService
{
    function show(Project $project, $id)
    {
        return $project->find($id);
    }
}