Member Since 4 Years Ago

Newcastle upon Tyne, UK

Senior Developer at Visualsoft Ltd

Experience Points 504,625
Experience Level 50

0 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 499
Best Reply Awards 682
Best Reply
  • 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.


    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.


    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.

15 Sep
1 day ago

martinbean left a reply on Best Way For Sub Apps In Laravel

@engrlaravel So you want to redirect somewhere after logging in? In that case, you'll need to override the redirect path to look up the user's company, and then redirect accordingly:

use Illuminate\Http\Request;

class LoginController extends Controller
    public function authenticated(Request $request, $user)
        // Look up company for user
        // Change this to however you associate a company with a user
        $company = $user->company;

        // Redirect to company URL instead of default redirect URL
        // If $company->slug is acme, will redirect to /acme
        // Again, you will need to change this if column name is different
        return redirect()->intended($company->slug);
12 Sep
4 days ago

martinbean left a reply on My Testing Taking Too Much Time To Pass

@omda Again, look at what your test case is doing and try and find any bottlenecks there. We can't really tell much from your phpunit.xml file.

11 Sep
5 days ago

martinbean left a reply on My Testing Taking Too Much Time To Pass

@omda Which test? Look into what the test is testing and find the bottleneck.

martinbean left a reply on Best Way For Sub Apps In Laravel

@engrlaravel I don't really understand. A URL is a URL?

10 Sep
6 days ago

martinbean left a reply on Best Way For Sub Apps In Laravel

my idea is to create folders (customer1,customer2...) inside laravel and re-upload whole application in each folder?

@engrlaravel So you want to maintain more than 200 applications?

Have middleware that inspects the incoming host name and try and match it to a customer. If there is a match, you can load your customer routes:

class DetectCustomerHostname
    public function handle($request, Closure $next)
        $hostname = $request->getHost();

        $customer = Customer::whereHostname($hostname)->first();

        if ($customer) {
            // Load customer routes

        return $next($request);
06 Sep
1 week ago

martinbean left a reply on Percentage Difference Between Dates

@inspiredprynce You still need a starting point! You can't just have a percentage between two arbitrary dates. That's like asking, what's the percentage between 10 and 15? Doesn't make sense.

martinbean left a reply on Laravel 6: What's Covered By Semantic Versioning

@alanstorm The public API of Laravel is the classes and methods you use. Going forward, any changes to these classes and methods that would "break" applications should become a major release. So expect these more frequently.

28 Aug
2 weeks ago

martinbean left a reply on XSS Vulnerability In

@itbazen Security issues are something you should keep private rather than publicly disclosing them.

If Jeffrey hasn't replied or addressed the issue, feel free to send him another email.

martinbean left a reply on Question Regarding Best Practice For Controller Methods

@tomhartley97 Closing an issue could simply be sending a PUT request to the URL for that issue and setting a status parameter or similar:

$client->put('/issues/{id}', [
    'form_params' => [
        'status' => 'closed',
27 Aug
2 weeks ago

martinbean left a reply on Anyway To Pass Parameter Into Eloquent Function?

@kankai You don't need to use scopes. Eloquent relationships return query builder instances, which you can add methods on to further refine the relationship:

$detail = $game_id->detail()->whereDate('created_at', '=' $date)->get();
23 Aug
3 weeks ago

martinbean left a reply on Migration Solution From Codeigniter To Laravel

@arjunkaimattathil Yes. It's called a development team.

There's no tool that will convert an application built in CodeIgniter to an application written in Laravel.

martinbean left a reply on Need Help With Laravel Model's Design

@aktheon I am struggling to work out what your model methods are doing. You say they are in a UserData class but then you are just using the DB facade?

If you have resourceful controllers, then just use the models as intended:

class UserDataController extends Controller
    public function index()
        return UserData::paginate();

    public function store(StoreUserDataRequest $request)
        return UserData::create($request->validated());

    // And so on...
22 Aug
3 weeks ago

martinbean left a reply on Track Down The Condition Of The Device In Database

@left A device has a current condition, so store it against the device. But by all means, store the condition against purchases as well (as I assume a device can degrade in condition over time, or be restored by an owner). The current condition of an item can then be changed between purchases.

martinbean left a reply on Route Model Binding

@jaheller If you are passing all three parameters to your controller action, you could look all three up using findOrFail() queries, then check each parameter belongs to the previous one.

Route::bind('{category}', function ($slug) {
    return Category::whereSlug($slug)->firstOrFail();

Route::bind('{subCategory}', function ($slug) {
    return SubCategory::whereSlug($slug)->firstOrFail();

Route::bind('{product}', function ($slug) {
    return Product::whereSlug($slug)->firstOrFail();
class ProductController extends Controller
    public function show(
        Category $category,
        SubCategory $subCategory,
        Product $product
    ) {
        abort_unless($product->sub_category_id == $subCategory->id, 404);
        abort_unless($subCategory->category_id == $category->id, 404);

        // Display product
20 Aug
3 weeks ago

martinbean left a reply on How To Design Multi Vendor Ecommerce

@remember-me Are you wanting something to do everything for you...?

You're asking a massively open-ended question. Try refining it a bit. It's like asking how to make Facebook, or Google...

martinbean left a reply on Multiple Laravel Codebases And User Tables

@laracastsluvr Why are you so hell-bent on having separate users? A user is a user. If your application has multiple front-ends, then use authorisation to restrict what a user can see based on their role.

martinbean left a reply on Laravel Nova Licensed

@deric1439 No. Nova works on trust as far as I am aware.

martinbean left a reply on How To Integrate Razorpay Payment Gateway In Laravel 5.5 ?

please give some suggestion how to integrate razorpay step by step

@van1310 No one is going to write you a step-by-step guide on how to integrate a payment gateway.

martinbean left a reply on Using Laravel Passport For User Authentication

Hi, is good using Laravel Passport for authenticating users?

@hakhsin As opposed to what?

martinbean left a reply on Laravel Nova Licensed

@deric1439 This exact use case is covered in the Nova FAQs:

Can I ship a copy of Nova in my own product? Nova is not intended to be bundled with any other product or service. However, the code you write for Nova (custom resource tools, metrics and cards, etc) are completely yours to do with what you like. That means you may charge for your Nova packages or any "pre-packaged" Nova resource, etc.

19 Aug
4 weeks ago

martinbean left a reply on How To Login/Register From Client Using API Token Authentication

@suli API tokens and Passport are pretty much the same thing when boiled down. Passport allows you to add OAuth to your application, in which your application will issue tokens that you can then use to make subsequent API requests. The "token" guard is just a simpler implementation where a token is stored with user records in your database, rather than issued via OAuth.

If you use the simple token approach, then you're going to need a registration endpoint that will create a user, generate an API token, and return that token to that user. The user will need to store it to then be able to perform any additional requests. If they lose that token, then there's no way to retrieve it (other than you going in the database, reading it, and sending it to the user, but you shouldn't be doing that).

With Passport, users can authenticate via OAuth. Again, you'll still need an endpoint to allow a user to register. After they've registered, they can use Passport to retrieve a token. There's the redirect flow where they're sent to a page in your application and asked if the app should have permission to use their account (similar to logging in with Facebook or Twitter). If the user accepts, they'll be sent back to the application with a code they can exchange for an access token. These tokens usually have a limited lifetime and issued in tandem with a refresh token that can be used to request a new, valid token when the current one expires.

13 Aug
1 month ago

martinbean left a reply on Product Architecture

@dippy How are users expected to log in to your system? Should they log in and out using each email address? Or can they log in with one email address and still access the other companies they are a member of?

martinbean left a reply on Laravel Shopping Cart Package

@adiksudip Well what are you requirements? Features? Number of products. "Best" is such a subjective thing.

martinbean left a reply on Constructive Feedback Request -- Controller Method Optimization

@jcgivens21 Looks like a good start. In response to your actual questions:

$this->validate: Should I move this validation logic into a Request class? Or is this generally overkill?

I always place validation in form request classes. I prefer my controllers to only be dealing with a valid request, not validate the request and then do the processing.

I'm creating the Employee here and saving it directly in the controller. Is it better to decouple this logic? I feel I've "slimmed" my controller based on the number of methods, but there's still a huge amount of text here, and I'm not sure if this is the best place to handle this Employee saving logic.

Instead of assigning each property individually, you could make your attributes fillable in your model and then use create():

$employee = Employee::create($request->validated());

Note: ->validated() will only work if your request does the validating.

In line with #2, there is some condition-based logic that when the user is inputting the employee data, they select whether the employee is paid Hourly or by Salary, and then I accept either of those values from the form, and I also calculate the other value even if it isn't sent and store both in the database table, in addition to whether it "is_salary" so I know when displaying the employee whether or not to display the values as hourly or salary. Condition-based logic like this is best in this controller logic?

This depends on a case-by-case basis. If I find theres lots of conditionally branching, I may move the code that deals with persisting a record to its own job class, and then dispatch that synchronously:

$employee = CreateEmployee::dispatchNow($request->validated());

Also with #3, there is some calculations being done in addition to the condition-based logic. Should calculation results be stored in the model/database tables or should those be handled real-time? It was simpler when I started to just store everything in the table without worrying about calculating these values upon request--but in proper design, should only 1 of those values be saved to the database and the other always calculated?

Again, it depends on a case-by-case basis. In this case, you seem to be manipulating one of two values depending if the employee is salaried or not. You could maybe move this logic to an mutator in that case:

public function setWageAttribute($value)
    if ($this->is_salary == 0) {
        $this->hourly_rate = $value;
        $this->salary = $value * 40 * 52;
    } else {
        $this->hourly_rate = $value / (40 * 52);
        $this->salary = $value;

This of course depends on is_salary being set on your Employee model instance first.

$employee->is_salary = 1;
$employee->wage = 40000;

Once the employee is added, I have a Toastr notification (basically a popup) that informs the user that their form submission was successful. I do this in basically EVERY function in the program, and in my blade template, it just picks up these Toastr notifications. I feel this is a very good implementation, and it works well for me, but I'm open to criticisms of this.

My only criticism is, its directly tied to an implementation. Personally, I just redirect and set success or error messages in the session:

return redirect()->route('event.index')->withSuccess('Event was deleted.');

Ill then have the view do something with that, i.e. display it in the header, as a toast pop-up, etc. If I want to change how flash messages are displayed on the front-end, then I just have to do it there rather than go through all of my controller actions and change instances of Toastr::success() to whatever Im going to use instead.

On the employee creation submit form, there are 2 submit buttons. One button (which is labeled "Submit" is just to submit the employee and then redirect the user back to the page that displays all employees. The second button is labeled "Submit & Return To This Page" and its function is to return the user back to the same form so that they don't have to click an additional button to get back here to add more employees. In the controller, I just check which button was submitted and redirect based on which button was pressed. Any thoughts on this setup?

No real thoughts. It's conditionally logic, so it's fine to have an if statement change where the controller redirects the user to.

Other general thoughts?

None other than those above! Essentially:

  • Put validation in form requests.
  • Try to use mass-assignment rather than setting properties individually.
  • Try to keep things generic, rather than tied to specific implementations.

Following the above, you may end up with controller actions that look like this:

public function store(StoreEmployeeRequest $request)
    $employee = Employee::create($request->validated());

    $url = $request->add_and_return_button ? back() : route('', $employee);

    return redirect()->to($url)->withSuccess('Employee has been added.');
12 Aug
1 month ago

martinbean left a reply on Sharing Users Between Multiple Laravel Projects

@jamespavett If you are going to have multiple applications authenticating against the same database of users, then I'd lean towards having a "single sign-on" server.

It will essentially be another Laravel application that contains your users and has Passport installed. Your applications would then authenticate against your Passport server.

If users should log in to your application using an email address and password, then you will want to use password grant tokens. If you want to redirect to your SSO server and have users approve or rejects your applications using their data (think authenticating with Facebook or Twitter), then you want to implement the redirect flow described here:

martinbean left a reply on Laravel Basics

define additional class files

@2015u058 Your question makes no sense. You put classes in their own files. No other file "defines" a class other than the file the class itself is in!

I suggest you watch some of the introductory videos here on the Laracasts if you're unsure which files to put classes in.

martinbean left a reply on How To Use Laravel Session?

@hjortur17 Usually you create an order in a "new" or "unpaid" state, redirect to the off-site payment gateway (passing the order ID), then your website marks the order as paid when returning from the gateway after a successful payment.

martinbean left a reply on Unable To Prepare Route [/] For Serialization

@tesoro Read the error message. It tells you exactly what the problem is.

LogicalException: Unable to prepare route[/] for serialization. uses closure.

Error messages are there for a reason. To tell you what has gone wrong and diagnose.

martinbean left a reply on Applying Authorisation Policy For Nested Resource

@pauladams8 Hey. Yeah, there seems to be two things at play in your example: authorisation (can this user view this question?) and data integrity (does this answer belong to this question? Does this comment belong to this answer?).

In this scenario, Ive opted for a separate middleware to do the data integrity checks and throw a 404 error:

class CommentController extends Controller
    public function __construct()

    public function show(Question $question, Answer $answer, Comment $comment)
        abort_unless($comment->answer->is($answer), 404);
        abort_unless($answer->question->is($question), 404);

        // If here then comment belongs to answer and answer belongs to question
09 Aug
1 month ago

martinbean left a reply on Handling Tweet Failures Gracefully

@ste You should have a queued job that dispatches the notification. You can then add a failed() method to the job that sends a different notification if sending the Tweet fails.

class SendTweetJob implements ShouldQueue
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $user;
    public $message;
    public function __construct(User $user, string $message)
        $this->user = $user;
        $this->message = $message

    public function handle()
        // Attempt to send Tweet here

            new TweetWasPostedNotification()

    public function failed(Exception $exception)
            new TweetFailedNotification($exception)

martinbean left a reply on Make API Call With Multiple Parameters

@pllaguno Yes, it is possible. Use query string parameters. That is what they are for. It is why it is called the query string.

You can then build URLs like:

martinbean left a reply on Laravel "Magic" Methods In Package

@snopz Ive just replied to this question on Stack Overflow.

Youre probably better off utilising Blades namespace and doing something like this in your controllers:

class FooController extends Controller
    public function fooAction()
        return view('theme::pages.home');

You can then switch the directory that Blade will looks for views in when it encounters the theme:: prefix:

View::addNamespace('theme', [

martinbean left a reply on When To Use Vue On Your Laravel Project ?

as much as possible , in my opinion

@maverickchan Why?

08 Aug
1 month ago

martinbean left a reply on Login With Plain-text Instead Of Hashed Password

@afrasiyabhaider Generate a password, send that password to the user:

// Generate a random, 20-character password
$password = Str::random(20);

// Create a user account
$user = User::create([
    'name' => $request->input('name'),
    'email' => $request->input('email'),
    'password' => Hash::make($password),

// Send new user their password
Mail::to($user)->send(new AccountCreated($password));

The only person setting a password for an account should be the owner of that account. Not an admin and not a developer.

martinbean left a reply on Login With Plain-text Instead Of Hashed Password

@afrasiyabhaider Passwords should not be viewable. Under any circumstance.

Why should I force him not to watch the password of students and teachers :D

Storing passwords in plaintext introduces two major attack vectors:

  1. If the database is compromised, an attacker now has all of the passwords in your application.
  2. People use the same password for multiple services. If the password from one service is discovered, then an attacker can try that password on other services: social media, online banking, etc. Not good.

Admin has to enter the roll number/ teacher id, so initially, the roll number will be set as the password for student and teacher id will be set as a password for teacher and these things will be hashed and stored in the password column of teacher and student.

Not good enough. A roll number is easily found. Especially if they follow some form of pattern (i.e. incrementing: 1000, 1001, 1002, ...). So there is nothing stopping someone logging in with another roll number.

You really need to have a bit of pride in yourself and tell your client that you will not compromise security because they say so. If they ask you to do something illegal are you just going to do it because they told you to? In fact, I imagine storing sensitive information (such as passwords) is illegal in some jurisdictions as you have a duty of care to take as many precautions as possible when it comes to security. Because it will you that will get sued if the application you build is compromised. Especially when dealing with a sector such as education and holding details of children.

07 Aug
1 month ago

martinbean left a reply on How To Properly Use Api Auth With Passport

@skycoder Passport uses the bearer token to look up the user associated with that token, so long as the token is valid and youre using the correct guard (usually api).

06 Aug
1 month ago

martinbean left a reply on Good PHP Design Issue

@kreghx Theres no hard and fast rule when it comes to structuring, organising, and writing code. If there were, machines would already be doing it ;)

In the case of lots of parameters in a class constructor, its an indication (and only an indication) that the class may be doing too much. Youll just need to look classes on a case by case basis when you find it requires lots of parameters to see if the class accurate models an entity in your application, or whether there may be smaller, more appropriate objects that could be extracted. Without concrete examples, thats hard to advise on.

In the example you did provide (the create payment class) it looks similar the subscription builder class in Laravel Cashier. I dont know your application, but I imagine a coupon is optional for creating a payment? If this is the case, then it doesnt need to be a parameter in your classs constructor.

Your class constructors should require the least number of parameters possible to instantiate a valid instance of that object. Any additional attributes can be supplied using other class methods (i.e. withCoupon($coupon)).

02 Aug
1 month ago

martinbean left a reply on How To Make The Url Seo Friendly.

am getting internal error 500

@ttfac01 Look inside your error log.

01 Aug
1 month ago

martinbean left a reply on Need Help In Integrating Repository Pattern

@kishanbhatt89 Laravels user providers already are an implementation of the repository pattern: theyre classes that conform to an interface for retrieving users.

Im not sure why youd want to refactor Laravels authentication system to use the repository pattern unless youve just read about the pattern and are now thinking everything needs refactoring to use a repository. Dont.

In 12 years of web development, Ive yet to see a nice implementation of repositories.

30 Jul
1 month ago

martinbean left a reply on Why Laravel Over Any NodeJS Framework For Your SPA?

@mikro123456 Well, I would use Laravel if I was using PHP and not JavaScript.

martinbean left a reply on How Does Fill Update Work With Password Field

@skycoder As @aurawindsurfing says, dont allow your password field to be filled using mass assignment like this. Instead, create a route and form specifically for updating the users password, like most other sites offer.

martinbean left a reply on Stripe, New European Regulation

@randyduran I'm not sure what youre asking? Stripe has had resources and next steps on how to make your integrations SCA-compliant, and has done for months now.

25 Jul
1 month ago

martinbean left a reply on Vapor - Taylor Otwell Presentation

Just back to the hotel after the second day of Laracon. What a blast!

As a Heroku customer, Vapor looks really interesting to me. Especially the $39/month price tag.

On first mention, I balked a little at that price point, but then considered that it is a one-off charge and I can host unlimited applications for that charge. Weighing up that I have multiple Heroku apps with at least two $7 dynos each (web and worker), then it looks like Vapor may work out cheaper than Heroku for me.

So looking forward to getting my invite, running an application on there for a month or two and seeing how the cost compares. Im already using SES, SQS, and S3 in my applications. I just need to see how the other costs (database, Lambda function invocations) compare to the ~$17/month Im paying per app on Heroku.

16 Jul
2 months ago

martinbean left a reply on Can Laravel Handle More Than 10K User At Same Time ?

@safin Laravel is just code. Itll be up your servers that dictate if your application can handle 10,000 users or not.