543 Best Reply Awards

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

17th February, 2018

martinbean left a reply on Pass Variable To Api Resource Collections • 4 days ago

@jlanzas You shouldn’t really need to. Resources are meant to change how a model is displayed. You shouldn’t be passing additional data to it.

15th February, 2018

martinbean left a reply on Laravel Ioc In Controller Constructor • 6 days ago

@baambaam If your controller is type-hinting SomeService, then it will be resolved by the service container.

14th February, 2018

martinbean left a reply on Caching API Repositories With Redis • 1 week ago

@StackBoot I gave you a pretty comprehensive example of how to cache repositories a few days ago:

martinbean left a reply on Stripe Integration Question • 1 week ago

@VikramBhaskaran request() is a helper method that accesses the current HTTP request. Passing it a string parameter (i.e. product) then accesses that attributed submitted as form data.

This question is why I prefer to be a bit more "explicit" in my code, and will do something like:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SomeController extends Controller
    public function someMethod(Request $request)
        $product = $request->input('product');

        // No question where product is coming from now

martinbean left a reply on Subscription Rates Increased? • 1 week ago

@VikramBhaskaran Don't hijack another thread.

If you have a question, then feel free to create a new thread containing it.

13th February, 2018

martinbean left a reply on Database Transaction Or Query->save() ? • 1 week ago

@AtomCoder Why don't you tell us more specifically what you're trying to do, rather than how.

martinbean left a reply on Why Cant I Access The Authenticated Users Id In The Constructor Of Controller Class • 1 week ago

@COACHTHEM Because controllers are instantiated before the authenticated user is resolved.

Instead, you will need to access users in the actions you perform actions:

class SomeController extends Controller
    public function someMethod(Request $request)
        $user = $request->user();


martinbean left a reply on Updating Repo After After Users Uploaded Few Images • 1 week ago

@Careless No. You should be storing "design" images somewhere under your public directory, say public/img, so you can reference them in your templates, style sheets etc.

martinbean left a reply on How To Properly Model This Context Using Eloquent? • 1 week ago

@johnnw This is a long</em post and therefore asking a lot. But is it not essentially just re-asking this same question from a few days ago?

martinbean left a reply on What Is A Good Approach To Getting Model Properties? • 1 week ago

@eb No matter how you access properties, you still need to refer to it somehow. So if you accessed a property via say $user->getAttribute('email') or $user->email(), you're still referring to it by the database column name.

Instead, think about your entities before modelling them and creating your database tables, like @authorvillar says.

martinbean left a reply on Updating Repo After After Users Uploaded Few Images • 1 week ago

@Careless You should keep images that make up your website's design under source control, but you shouldn't store user-uploaded content in your repository.

martinbean left a reply on No 'Access-Control-Allow-Origin' Header Is Present On The Requested Resource. • 1 week ago

@GTHell The issue is with LinkedIn: the error message is telling you the requested resource (i.e. LinkedIn's API) doesn't have the header present.

martinbean left a reply on Check Current Time Is Between Opening And Closing Time • 1 week ago

@NadeemAkhter Why would it return false when the branch is open? The method is called is_open.

12th February, 2018

martinbean left a reply on Large Scale Project Design • 1 week ago

@ochirach Building a "large" application is no different to building a "small" or "medium" application, you just have more files.

Any application starts with modelling your entities. If you didn't get your models and relationships right at the beginning then that will only cause problems down the line. Once you have defined your entities, you can create resourceful controllers around them.

10th February, 2018

martinbean left a reply on Authorization For API: Laravel Policies And Gates VS Passport Scopes • 1 week ago

@mdtsoy A good way to think about this is: you can tweak your gates/policies at any time, but once a user’s authenticated via OAuth and been granted scopes, you cannot change those without getting the user to re-authenticate.

Therefore, OAuth scopes should be really high-level permissions. “read” and “read/write” are common options. You can then use policies to determine what resources a particular user has access to. For example, a user may only be able to edit their own posts. That logic would live in a policy.

martinbean left a reply on Google Amp On Laravel App • 1 week ago

@haizone AMP is trimmed-down HTML, so you need to create routes that serve your content in an appropriate HTML template.

martinbean left a reply on Repository Pattern With Caching Laravel • 1 week ago

@StackBoot I don’t know any off the top of my head, but it’s just a case of having two classes implement the same interface, and then decorating the base repository with your caching one in the service container:

interface UserRepository
    public function all();
    public function find($id);
class EloquentUserRepository implements UserRepository
    public function all()
        return User::all();

    public function find($id)
        return User::find($id);
class CachingUserRepository implements UserRepository
    protected $users;

    public function __construct(UserRepository $users)
        $this->users = $users;

    public function all()
        return Cache::remember('users.all', $minutes = 10, function () {
            return $this->users->all();

    public function find($id)
        return Cache::remember("users.{$id}", $minutes = 60, function () use ($id) {
            return $this->users->find($id);
class RepositoryServiceProvider extends ServiceProvider
    public function register()
        $this->app->bind(UserRepository::class, function ($app) {
            return new CachingUserRepository(
                new EloquentUserRepository

    public function provides()
        return [

With the above, when you type-hint UserRepository, you’ll get an instance of CachingUserRepository, which wraps the EloquentUserRepository.

9th February, 2018

martinbean left a reply on What Environment Does Tayloy Otwell Use? MAMP, Docker, Native Or What? • 1 week ago

@marknt15 Horses for courses.

Copying someone else’s set-up isn’t going to immediately make you a better or more efficient developer, especially if it’s introducing something new and unfamiliar to your set-up. It’s just going to make your frustrated as to try and “match” someone else’s productivity.

Instead, experiment with tools yourself. See what makes you more productive. The types of stuff Taylor’s working on (frameworks and packages) may mean he has a set-up that’s great for that type of work, but not so for “regular” application development.

martinbean left a reply on Controlling Child From A Parent • 1 week ago

@ArchStanton I think events may be more appropriate:

8th February, 2018

martinbean left a reply on Queued Job - Best Way To Wait For An External Event • 1 week ago

@ohffs Are you able to fire an event at all when a torrent’s finished downloading?

martinbean left a reply on Caching E-commerce Catalog Site • 1 week ago

@jandk4014 Spidering your site for every possible query string permutation to “pre-cache” things sounds like an intensive and wholly impractical solution. Instead, I’d be more worried about this statement:

On a very query intensive page I could have in excess of 150 queries

Work out why a single page is performing 150 database queries. No page should be performing that many queries. So see if there are some relationships that can be eager-loaded. Or if you have a dynamic menu coming from the database, cache that (as it’s not going to change from page to page unless an administrator modifies the menu in the admin panel).

martinbean left a reply on Which Series To Learn Vue.js ? • 1 week ago

@francoboy7 Just start with the Vue 2 series. It’s the current version.

martinbean left a reply on Atom Editor • 1 week ago

@clod Not that you’re biased or anything…

7th February, 2018

martinbean left a reply on Correct Work Flow Between Tasks/Jobs/Notifications • 2 weeks ago

@skiedude Schedule a command to run once each day that looks up expiring records, and in that command queue the notifications.

martinbean left a reply on Create A New Controller For OAuth Or Just Use A Default Auth Controller? • 2 weeks ago

@johnnw You should create a controller per service, as per the documentation:

6th February, 2018

martinbean left a reply on Route Model Binding Key Name • 2 weeks ago

@votemike It’s a route parameter. It corresponds to an entity, not how that entity’s retrieved. Otherwise, what if you have a route with two parameters that routed with slugs? You can’t have /series/{slug}/episodes/{slug}.

Instead, parameters describe the entity being routed, and a resolved model instance is then passed to your controllers’ actions as parameters. When you think of it like that, it then makes more sense why a route parameter would be something like {series} and not {slug}.

martinbean left a reply on Route Model Binding Key Name • 2 weeks ago

@votemike The variable name should match the route parameter, i.e. $item if your route key is {item}.

martinbean left a reply on When To Make The Switch To Bootstrap 4? • 2 weeks ago

@cruskai Yeah, Bootstrap took a weird stance with versioning.

When they launched one of the betas, they said that Bootstrap 3 was then deprecated, so there was a period where there no official version of Bootstrap.

Bootstrap 4 is now out of beta though and has been released proper, albeit with a few teething problems, but they should be ironed in a future patch release.

martinbean left a reply on Using Unique Validation Is Store() And Update() • 2 weeks ago

@bwrigley I specify the rules in an array (with one element per line, and also give the “unique” rule a key:

'longTitle' => [
    'unique' => Rule::unique('practitioners')->ignore($id),

It seems to satisfy my OCD when it comes to “code neatness”! Ha-ha.

martinbean left a reply on How To Use Queue Fake For Testing • 2 weeks ago

@musicliftsme Pretty much. You fake the queue, try pushing a job, and then assert the job was pushed on the queue as expected, without actually pushing it.

// Fake the queue

// Push a job

// Assert the job was pushed to the queue

martinbean left a reply on What Are Jobs & Queues? • 2 weeks ago

@SalmanPatnee Jobs and queues have been in Laravel long before version 5.5.

A job is a self-contained class that does a particular task: send an email, mass-update some database records, resize an image, etc.

A queue is fed jobs and processes them outside of your web application. You can place a job on a queue, and let your user go on with their day as normal.

martinbean left a reply on Using Unique Validation Is Store() And Update() • 2 weeks ago

@bwrigley The alternative is the “string” format:

'longTitle' => 'required|unique:practitioners,id,'.$id,

But to me, the string concatenation is worse than having one rule use the fluent rule builder syntax in there.

martinbean left a reply on Laravel Certified Exam • 2 weeks ago

@komalbhatt Yes, there’s a Laravel Certification programme. As @topvillas says, you could have found it with a quick search. The top result is a page on the domain, so it’s as authentic as it can be.

5th February, 2018

martinbean left a reply on Login Users Without A Database! • 2 weeks ago

@Milado Your user provider should be hitting the Azure API instead of query a database table. You will therefore need to create a new User model that implements the Authenticatable contract, as described in the Laravel documentation:

martinbean left a reply on Automatic Currency Formatting Based On App Locale • 2 weeks ago

@lwvvliet What you want exists in “raw” PHP: the money_format function.

As per the first comment, you can use %.2n to format the amount with the currency symbol (i.e. $ instead of USD).

martinbean left a reply on Is It Possible To Make A Request Wait For An Asynchronous Queue Job To Finish? • 2 weeks ago

@LasseHaslev If you’re waiting for a queue job to finish before continuing with something, then it’s no longer asynchronous (and in fact synchronous), it which case you may as well not use a queue (as one of their advantages is to process tasks in the background).

martinbean left a reply on Error In Npm Run Dev • 2 weeks ago

@afoysal Well, you’re getting an error message telling you exactly what’s wrong:

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

So have you tried enabling strict mode (by adding "strict mode"; to the top of the file where you use let / const / function / class?

martinbean left a reply on DI Services Using Auth Into Controller Constructor • 2 weeks ago

@Jantlap Controllers are instantiated before the authenticated user is resolved, so you cannot access the logged-in user in controller constructors.

Instead, you’ll need to access them in your controllers’ methods:

class SomeController extends Controller
    public function __construct()
        // Auth::user() does not work here, because controllers are instantiated
        // before AuthServiceProvider class is booted

    public function someMethod(Request $request)
        // Instead, you can access Auth::user() or $request->user() here

martinbean left a reply on Laravel 5.6 • 2 weeks ago

its out now

@anilatlaracasts No, it’s not. It’s due for release following Laracon Online on February 7.

martinbean left a reply on Laravel Socialites Facebook Redirect Error • 2 weeks ago

@JustineRebecca You have a few typos (missing quote mark in env('FACEBOOK_CLIENT_ID) and a space in Route: :get()).

Also, you’ll need to regenerate your application’s secret key since you’ve included it in your post. People can now use this to make malicious requests as your application.

martinbean left a reply on Should I Change 'name' In Composer.json, From 'laravel/laravel' To The Name Of My Own Project...? • 2 weeks ago

@miwal Nope. Once you’ve created a Laravel project you’re free to modify the name in the composer.json file to be that of your project’s. It’s also a good idea to set license to proprietary too.

martinbean left a reply on How To Rerequest Email While Authorizing With Facebook (laravel/socialite) • 2 weeks ago

@aurawindsurfing It’s more connecting a Facebook profile (“This site wants to use your Facebook data”) then registering. When you’re get that prompt, you can actually toggle the permissions requested before redirecting back to the third-party application. One of these permissions is email.

Facebook has a separate product for user authentication, coincidentally named Facebook Login.

martinbean left a reply on It Works But I Would Like To Do It Better (modify Values In Collection) • 2 weeks ago

I’d highly recommend against modifying attribute values in your models, as it makes getting the original value nigh-on impossible.

For example, mutating a start_date attribute to a formatted date string then makes it impossible to access the underlying date as a Carbon instance without horrible workarounds.

Instead, consider mutating attributes using a different name, i.e.

class Call extends Model
    protected $dates = [

    public function getStartDateFormattedAttribute()
        return $this->start_date->toDateString();
$call->start_date; // start_date as Carbon instance
$call->start_date_formatted; // start_date mutated to date string

martinbean left a reply on How To Rerequest Email While Authorizing With Facebook (laravel/socialite) • 2 weeks ago

@Tarasovych Further down in that file you linked to in your original post, there’s a method to re-request previously declined permissions:


martinbean left a reply on Dealing With Differences Between Sqlite And Mysql • 2 weeks ago

@crisward Depends what the issues you’re having are.

martinbean left a reply on 5.6 - Not That Many Feature List? • 2 weeks ago

@shez1983 There has been features added if you read the changelog:

It’s just the features aren’t huge, new components like a notification system or similar. However, the framework has began to use version 4 of Symfony’s components under the hood, which means the framework number needs to be bumped.

martinbean left a reply on Weird Api Behaviour Or Am I Stupid? Halp! • 2 weeks ago

@larafam I appreciate you thinking of me, but please don’t tag me (or other users) to draw you to your question. I do have a full time job and browse this forum when I can, and treat everyone’s questions with equal priority. I’m not free, on-call support.

Edit Your Profile

Want to change your profile photo? We pull from