phildawson

phildawson

Member Since 4 Years Ago

Oxford, UK

Experience Points
125,150
Total
Experience

4,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
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.

Level 26
125,150 XP
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.

How about this?

interventions
id 

intervention_patients
id intervention_id patient_id

patients
id

diagnostic_intervention_patient
diagnostic_id intervention_patient_id

diagnostics
id
class Intervention
{
    function interventionPatients()
    {
        return $this->hasMany(InterventionPatient::class);
    }
}

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

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

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

class Patient
{
    function interventionPatients()
    {
        return $this->hasMany(InterventionPatient::class);
    }
}

class Diagnostic
{
    function interventionPatients()
    {
        return $this->belongsToMany(InterventionPatient::class);
    }
}
foreach($patient->interventionPatients as $interventionPatient) {

    foreach($interventionPatient->diagnostics as $diagnostic) {

    }
}
    foreach($interventionPatient->diagnostics as $diagnostic) {

    }

phildawson left a reply on Model HasManyThroughMany Relationships

Edit: Ignore this

Based off the init description of the relationships

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

and your aims

  1. retrieve patient diagnostics (all the diagnostics regardless of which intervention it happened in)
$patient->diagnostics;
  1. only the diagnostics for that patient on that intervention.
foreach($intervention->patients as $patient) {

    $patient->diagnostics;
}
05 Oct
3 years ago

phildawson left a reply on Set Custom Header For Any Response

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

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

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Response;
use Illuminate\View\View;

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

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

        return $response;
    }
}

phildawson left a reply on Set Custom Header For Any Response

  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;
    }
}
  1. Open \App\Http\Kernel.php and add to $middleware if you want it on all
 \App\Http\Middleware\NoCache::class,

or define the key to pick and choose.

'nocache' => \App\Http\Middleware\NoCache::class,

Done.

phildawson left a reply on Route Groups Inside A Resource

Does it need 'templates' in the url?

http://laravel.com/docs/5.1/controllers#restful-nested-resources

Route::group(['prefix' => 'api', 'middleware' => ['api.auth','user.workspace'] ], function() {
    Route::resource('workspaces.categories', 'WorkspaceCategoryController');
});

http://localhost/api/workspaces/1/categories/1

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

DO do $5 monthly. Almost like free, or a price of a sandwich https://www.digitalocean.com/pricing/

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

@lstables This should be the same. You have to make the .env and set the key.

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);
➜  test  php artisan --version
Laravel Framework version 5.1.19 (LTS)

The only diff I spotted is the corrected default path is database/database.sqlite https://github.com/laravel/laravel/commit/879bc146504462ef273b893010edf004026aa021 http://cabinet.laravel.com/latest.zip

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

https://byet.host/free-hosting

Free Hosting Plan: Along with all this, we provide free FTP, PHP 5.4, MySQL and our very popular feature:

Boo.

02 Oct
3 years ago

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

@itcan

  1. So I would comment the default MailServiceProvider in 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']);
    }
}

I haven't tested any of this but that should work.

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. The root should be like:

/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 new-d up directly in the method $client = new HttpClient; and not resolved out the container it's pointless binding like so which would be fine normally.

<?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;
});

I can't see how a global options can be set.

@pmall any ideas?

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 if it's specifically for Mandrill.

    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']);
    }
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 model event keys are named as "eloquent.{$event}: {$name}" eg "eloquent.updated: Foo"

You really don't want to be doing this though.

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

@snapper

users
id name

transactions 
id given_to received_from

You have to let it know the relationship. In this case they belong to, and you need to specify the column it will be making the join on otherwise it'll be looking for a given_to_id column by default.

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

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

then you can use it like you had

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

phildawson left a reply on Getting Errors In Production Only

@Man

Put the relationship in the Model

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

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

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

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

The views job is just using those params passed through, don't do any retrieving of data, or extensive data manipulation here. Just think echo, ifs and foreachs

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

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

<?php endforeach;

phildawson left a reply on Entities Tightly Coupled With Eloquent

Re the first you can quite easily make use of the repository pattern and it can then operate without having a need to know what specific implementation it's using as long as it meets the interface/contract its happy. With ORM the entity in the implementation will always need to have knowledge of its storage, even if it's done by annotation rather than inheriting. You may/may not have seen this http://www.laraveldoctrine.org/docs/1.0/orm/entities

Re the second concern. 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();
foreach($user->books()->get() as $book)

vs

$user->book;
foreach($user->books as $book)

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.

Making use of the __get is a positive thing. When you do $user->name; the name isn't a property of the user object either. I mean it's not doing this

class User 
{
    public $name = 'bob';
}
$user = new User;
$user->name;

its more like this

class User 
{
    protected $attributes = [
        'name' => 'bob'
    ];
    
    public function __get($key)
    {
        return $this->attributes[$key];
    }
}
$user = new User;
$user->name;

So logically following on the concern, you should also have another concern you aren't calling actual getter methods.

class User 
{
    protected $name = 'bob';

    public function name()
    {
        return $this->name;
    }
}
$user = new User;
$user->name();

Are those genuine concerns?

Nah, its all too easy to overthink I find :) Embrace the Eloquent!

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

I would do it like so as a basic starter, probably have a method called similar like @sid405 and excludes itself from the results.

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) // null->id

Everything works well locally.

I'm guessing the entries in the posts table are different, and the one on the production can't find the other by the 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 Apache/2.4.12 or network rather than your code. Try just a single resource which should be instant but takes like 20 seconds, you can see the stream of content loading.

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

@ralee Care to share the url?

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

But I know that the requirements are PHP 5.6 or newer for the Laravel 5.1.

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

http://laravel.com/docs/5.1/installation

But seriously I'd drop any provider thats not on 5.6 with no prevision to upgrade it.

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

@lstables 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 use the except method.

The opposite method is only() if you want to whitelist, rather than blacklist.

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

@Sithu Or use the DB statement to add a proper YEAR col..

public function up()
{
    .. 

    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

You don't need the =

The auth()->user()->id can just be auth()->id

I'm guessing you want to order by the latest using latest(). If you want to order 'asc' use oldest().

It'll use created_at unless you pass the column.

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

In fact just like @Rtransat but a bit shorter

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 naturally be this

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

But I think you need to select them first.

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

an so forth.

If the .env contained every config it would be super long.

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

@souleye

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

when you make the change, you'll prob need to close Terminal and reopen. Try your full path rather than ~

Once all thats working see:

http://ohmyz.sh/

https://www.iterm2.com/

:)

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.

edit

~/.bash_profile

add

export PATH="/Users/yourusername/.composer/vendor/bin:$PATH"

save reopen Terminal

phildawson left a reply on Models & Objects

@tenyardtech

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.

I'd get some sleep though, if you think you need sleep, then you def need it.

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

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

the only mistake is its += for the combined operator

phildawson left a reply on Need Help With Model Binding

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

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

RouteServiceProvider::boot

use App\Article;

at the top and then in the boot

public function boot(Router $router)
{
    parent::boot($router);

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

However try and name your all models singular though so 'Known'.

Name all tables plural.

When it comes to naming methods make them singular if the relationship is belongsTo or plural if a many.

Also if you name the table/cols like so then no other config is needed on the models.

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 user()
    {
        return $this->belongsTo(User::class);
    }

    function typeSpecialist()
    {
        return $this->belongsTo(TypeSpecialist::class);
    }
}
class TypeSpecialist extends Model
{
    function knowns()
    {
        return $this->hasMany(Known::class);
    }
}
$user = User::find($id);

foreach($user->knowns as $known) {
    echo $known->typeSpecialist->name;
}

or

$knowns = Known::all();

foreach($knowns as $known) {
    echo $known->user->name;
    echo $known->typeSpecialist->name;
}

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, someone prob posting and then deleting. 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

remove / before the substitution

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

The regex says capture (.*) everything from the start ^ to the end before the slash /$ and substitute it with what it found.

Basically you don't want to be prepending a slash to the result.

But really your DocumentRoot should be /var/www/html/rnd/public not /var/www/html

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, and throwing in a param for good luck.

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

});

Note you can also do the Class@method syntax app()->call('App\Services\ProjectService@show', [4]);

<?php

namespace App\Services;

use App\Repositories\Contracts\Project;

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

Much clearer with dependancies in the construct imo.

25 Sep
3 years ago

phildawson left a reply on Method Dependency In A Services Class

Ah hang on..

This returns a must implement interface, none given error.

Is your concrete implementing your contract?