martinbean

Senior Developer at Pfizer

Member Since 6 Years Ago

Newcastle upon Tyne, UK

Experience Points
674,505
Total
Experience

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
595
Lessons
Completed
Best Reply Awards
896
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

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

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 50
674,505 XP
Mar
06
1 day ago
Activity icon

Replied to Can I Use Jetstream With RESTful API?

@mbnoimi Jetstream is a UI starter kit. It doesn’t have API endpoints as it’s not meant to be used as an API.

If you want API authentication, then use a more appropriate package such as Sanctum or Passport.

Activity icon

Replied to How Would You Usually Organise Your Ajax Methods In Laravel?

@boubou If I’m making requests with AJAX, then I’m usually hitting API endpoints that return JSON and not HTML.

Activity icon

Replied to Amazon Style Product Variation/Options

@laracastsluvr When dealing with physical products, you will normally have multiple SKUs for a single product, with each SKU representing a particular variant of a product. So if you have a t-shirt product, you’d have a SKU for every possible colour and size combination that t-shirt is available in (L/red, L/blue, etc). So I’ve modelled many ecommerce sites this way: a top-level Product model with a has-many relation to a Sku model.

If you want to add attributes then you could add a model for that, too. At its simplest, your Product model could have many Attribute models. This model would contain the name of the attribute only (i.e. size, colour, etc). You could then have a many-to-many relation between your SKUs and its products attributes (attribute_sku pivot table), that has the value for that SKU and attribute combination as a pivot value. So for SKU X, you might say for attribute Y (size) the value is “L”, and for SKU X and attribute Z (colour) the value is “red”. You then know that SKU X is the red, L t-shirt.

Back to your UI, you can then build your attribute select lists so that if you choose size L, then it shows all SKUs whose value is “L” for the size attribute, and your colour options are updated to show all the colours available for that sized shirt. And when you select a colour, it will most likely match a single SKU so you can show the price for that shirt in the selected size and colour.

Activity icon

Replied to One Guard, Multiple User Types

@topvillas I wouldn’t use guards at all for this.

If you have a polymorphic “profile”-like relation on your user models, then I’d just have middleware that checks the profile type on type of your standard auth middleware:

Route::middleware(['auth', 'profile:foo'])->group(function () {
    // Routes that only users with a "foo" profile can access
});
Mar
05
2 days ago
Activity icon

Replied to How To Protect Register Route And View In Jestream For Guest

in some companies, an admin registers (enters) a new user.

@jlrdw and in those companies, there’ll be an admin panel to manage users.

Exacly! Taking advantage, could you give me an example of code using gate or police?

@felipesmendes Then create a user controller in your admin panel instead of (wrongly) trying to reappropriate the register route.

If an admin can create other users, then you’re probably also going to want routes to list, edit, and delete users too. You’re not going to get that with just a register endpoint.

Activity icon

Replied to How To Protect Register Route And View In Jestream For Guest

@felipesmendes How on earth does that work? If you’re logged in, why would you be registering again?

Activity icon

Replied to Class 'Laravel\Socialite\SocialiteServiceProvider' Not Found

You need to upload any files locally that aren’t on your server. Otherwise your project isn’t going to work.

Activity icon

Awarded Best Reply on How Do You UNIT Test Your Controller?

@kevdev You wouldn’t unit test a controller. A unit test should test one single unit of code (such as a method) without dependencies. It’s nigh-on impossible to unit test a controller because it relies on so much context: a router, middleware, requests and responses, etc.

You’ll find difficulty unit-testing a controller as Laravel’s unit test classes extends PHPUnit’s base TestCase class. Instead, you’ll need to create a feature test, which boots the framework in their setUp methods, and will give you helpers for testing HTTP requests such as $this->post, $this->assertSuccessful, etc.

If you’re writing a unit test and struggling because you need access to the framework, or resources like a database, then that’s a good indicator that what you’re writing is not a unit test.

Activity icon

Awarded Best Reply on Javascript , How To Verify If A Property Of An Object Exists Or Not?

@godzilaravel For checking deeply-nested properties like that, I tend to just do what you’re doing, but slightly terser:

if (this.var1 && this.var1.proper1) {
    // this.var1.proper1 is defined
}
Activity icon

Replied to Class 'Laravel\Socialite\SocialiteServiceProvider' Not Found

Because you need to upload all of your dependencies to your server, and generate the autoload files on the server.

If Laravel is complaining it can’t find a class, then it can’t find the class, which means one of two things:

  1. You’ve not actually uploaded the file.
  2. Your autoload files haven’t been generated.

So, investigate the above.

Activity icon

Replied to Laravel + Vue Server Side Rendering

@frazecolder That’s not what server-side rendering is for. Server-side rendering is for pages that are literally built from Vue, i.e. single-page applications.

You can’t server-side render fragments of pages; your Blade template is compiled on the server-side. If that Blade template contains Vue components, then they’ll be invoked in the browser.

Activity icon

Replied to Class 'Laravel\Socialite\SocialiteServiceProvider' Not Found

@tehseen Have you actually installed your Composer dependencies on your server?

The error message is telling you what’s wrong: it can’t find a class. So you’ve either not actually uploaded the class to your server, or you haven’t generated your autoloader properly.

Activity icon

Replied to How To Add Headers (Expires, CacheControl) To A File Uploaded To Amazon S3 Using The Laravel 7.30.4 Storage Facade

@prateek srivastava Well how are you actually retrieving the file? Those headers are set on HTTP responses; not as metadata on the file itself.

Activity icon

Replied to Javascript , How To Verify If A Property Of An Object Exists Or Not?

@godzilaravel For checking deeply-nested properties like that, I tend to just do what you’re doing, but slightly terser:

if (this.var1 && this.var1.proper1) {
    // this.var1.proper1 is defined
}
Activity icon

Replied to CREATE REST API WITH OR WITHOUT FRAMEWORK?

So why are you asking the question if you‘ve already decided on the path you’re going to take…?

Activity icon

Replied to CREATE REST API WITH OR WITHOUT FRAMEWORK?

@lazaros.papanikolaoy@gmail.com As mentioned by @snapey, the level of effort.

If you don’t use a framework, then you’re starting from scratch and have to do all the same, repetitive tasks such as setting up a router, handling HTTP requests, returning HTTP responses, middleware for any caching or content negotiation… Basically all the stuff you get out of the box with a full stack web framework like Laravel.

So, do you want to spend works laying the foundation and writing code to solve problems that have already been solved a thousand times before you? Or do you just want to start writing the code for your application, which you can do if you just start with a clean installation of something like Laravel?

Activity icon

Replied to How To Delete S3 Image In Feature Test?

Yes. Once you’ve swapped a disk with a fake, you then use that disk like you would normally.

If you’re still having issues, then show your test. We can’t help you without seeing any code.

Activity icon

Replied to How Do You UNIT Test Your Controller?

@kevdev You wouldn’t unit test a controller. A unit test should test one single unit of code (such as a method) without dependencies. It’s nigh-on impossible to unit test a controller because it relies on so much context: a router, middleware, requests and responses, etc.

You’ll find difficulty unit-testing a controller as Laravel’s unit test classes extends PHPUnit’s base TestCase class. Instead, you’ll need to create a feature test, which boots the framework in their setUp methods, and will give you helpers for testing HTTP requests such as $this->post, $this->assertSuccessful, etc.

If you’re writing a unit test and struggling because you need access to the framework, or resources like a database, then that’s a good indicator that what you’re writing is not a unit test.

Activity icon

Replied to Info Frontend / Backend / Api Structure

my two questions are these: the api controller have to stay on the frontend or backend? example.com/api/ecc or admin.example.com/api/ecc

@yohannes81 An API is neither front-end or back-end.

I would like no one to know the address of the backend

That’s not going to be possible if your “front-end” is consuming your API. All someone has to do is open the dev tools in any modern browser and they can see what URLs your application is making requests to, including any APIs.

the other question is about file storage. Which of the two domains should it be in?

if i had to have a mobile app tomorrow, should i use amazon s3?

Why would file storage be in any particular domain? I assume files will be consuming in both the front-end and back-end. So yes, S3 would be an appropriate location, especially if you’re planning to support other, non-web apps such as mobile apps.

Activity icon

Replied to Which Approaches Better For REST API Params?

@crazylife I don’t really understand your question. Store what data as history? Pass the ID field of what?

Can you explain what it is you’re actually trying to?

Activity icon

Replied to Laravel Passport Refreshing A Token Manually

@mulugu You shouldn’t be refreshing tokens. The client should be using a refresh token to extend a token’s lifetime if they need to.

It defeats the point of tokens with a limited lifetime and weakens security if you’re just extending tokens on the server side.

Activity icon

Replied to Can The Laravel Queue System Be Used For Communication Between Two Laravel Applications?

@bobmulder I’d say web hooks is the better pattern if you want App A to send some data to App B.

App A can use a queued job itself to dispatch the webhook, and remove the job if App B responds with a successful response (200 OK or something to indicate they received the webhook). If there’s an error, the webhook data goes back into the queue to be attempted again. If it fails x amount of times, you can move it to your failed_jobs table and investigate why the webhook isn’t getting delivered.

Mar
04
3 days ago
Activity icon

Replied to Using Resources On API Calls

@jwhm This isn’t what API resource classes are for.

Consider using a data mapper or something that takes the response from the third party API, and returns an object containing just the fields you’re interested in.

Activity icon

Replied to Defined Namespace In The Route Group

@beginnersoul You don’t need to define a namespace if you’re just going to use the ::class-based syntax, as that will use the fully-qualified class name (including namespace) any way.

Activity icon

Replied to Re-use QueryScope As Attribute

@deansatch No, because scopes add query builder methods, and an accessor in your case will just do some Boolean logic on attribute values.

Activity icon

Replied to Can We Remove Default Service Providers From Laravel?

@pushpak130001 Don‘t use a framework at all if that worried about a few milliseconds 🙃

Activity icon

Replied to Global Scope On Model Breaks My Laravel Scout:import Command

@another_x Been there, done that. Only advice I have is: don’t add global scopes that rely on context like this to your models.

I built a multi-tenant platform years ago where I had a global scope to restrict it to the owning tenant, and spent more time battling it, forgetting to add withoutGlobalScopes etc, that I just rebuilt the app.

The workarounds are almost worse than the problem itself. Your models should not be checking if they’re running in a CLI environment; your models just shouldn’t be reaching out and checking environmental stuff like that at all. Models are data.

Just add a tenant relation to your models, and query your models using a particular tenant as the aggregate root:

Route::domain('{website:domain}')->group(function () {
    Route::get('articles', '[email protected]');
});
class ArticleController extends Controller
{
    public function index(Website $website)
    {
        $articles = $website->articles()->latest()->published()->paginate();

        return view('website.article.index', compact('articles'));
    }
}
Activity icon

Replied to How To Delete S3 Image In Feature Test?

@crazylife If you’re faking the disk then Laravel will replace the configured disk with the fake one: https://laravel.com/docs/8.x/mocking#storage-fake

Mar
03
4 days ago
Activity icon

Awarded Best Reply on Asking For A GIT Workflow Recommendation

@punksolid Sounds like you would have a “base” repository, and a fork of that repository.

Maybe the open source one is the base repository, and the “private” repository is the fork. You make your bug fixes and features in the base repository, and then pull them into the fork.

Activity icon

Replied to How To Check Laravel CPU Usage In Shared Host?

@stratboy Shared hosts probably won‘t show you information like that because, like the name says, it’s shared hosting, so resources—such as the CPU—are shared between each customer using that particular server. You’ll just get told when you’re exceeding your quota.

Instead, you’ll need to profile your code as @bugsysha says and see if there are any CPU-intensive parts.

Activity icon

Awarded Best Reply on Mail Configuration In Controller

@mofish Why can’t a user just set their mail variables in their own .env file? Again, that’s what it’s for.

Activity icon

Replied to Anonymous Android

Probably worth firing Jeffrey an email. I know I wouldn’t be checking my notifications for a discussion forum as busy as Laracasts’ 😄

Activity icon

Replied to Mail Configuration In Controller

@mofish Why can’t a user just set their mail variables in their own .env file? Again, that’s what it’s for.

Activity icon

Replied to When Do You Specify Column Name In Eloquent Relationship?

@nickywan123 As long as you stick to Laravel’s naming conventions then yes, it will be able to “guess” your column names.

Activity icon

Replied to Calculate Price Within Model Which Depends On Data From Another Model

@baserider Don’t edit your question. Leave the question and post the answer so it can be of help to anyone else who may have had the same issue.

Activity icon

Replied to Encapsulate AMP Code In Javascript

A good analogy would be Google Adsense or several other ad networks that give Javascript to publisher and when placed on a website it shows either a link, banner or a form to fill.

@singh This completely goes against what AMP is for though, where you don’t just drop chunks of vanilla JavaScript in your page, and instead build your page using components.

For example, for adverts, you don’t copy and paste a JavaScript snippet. You use an appropriate, corresponding component such as <amp-ad> to display an ad in your page.

Activity icon

Replied to How To Remove This Laravel Symfony\Component\HttpFoundation\ParameterBag Package ?

@riwash Well why have you decided you need to remove the package in the first place? Because Laravel does use it…

Activity icon

Replied to Mail Configuration In Controller

however wondered if it is possible to change the email configuration in the controller instead of loading them from the mail.php file

@mofish That’s literally the entire point of the configuration file, though.

Just how often are you changing your mail settings that they need to be done in an admin panel, and you can’t just update an .env file or environment variables…?

Activity icon

Replied to Asking For A GIT Workflow Recommendation

@punksolid Sounds like you would have a “base” repository, and a fork of that repository.

Maybe the open source one is the base repository, and the “private” repository is the fork. You make your bug fixes and features in the base repository, and then pull them into the fork.

Activity icon

Replied to What Color Should Be Used For Website For Acting Jobs

@deep88 Research other acting websites and see what colours are predominantly used there. But, there’s no point just picking a colour if you don’t know why it was picked in the first place.

Activity icon

Replied to Anonymous Android

@snapey Is it not using Gravatar or something?

Mar
02
5 days ago
Activity icon

Awarded Best Reply on Is It Okay To Use Fortify In Combination With Breeze?

@imbee Fortify is a headless authentication system, so you shouldn’t be using it with a starter kit like Breeze.

If you want 2FA, then use Jetstream, which is built upon Fortify.

Activity icon

Replied to Is It Okay To Use Fortify In Combination With Breeze?

@imbee Fortify is a headless authentication system, so you shouldn’t be using it with a starter kit like Breeze.

If you want 2FA, then use Jetstream, which is built upon Fortify.

Activity icon

Replied to Handling Multi Currency Subs

@moonfive You’ll need to create separate prices for each currency you support, yes.

Most subscription companies use local pricing. So for example Netflix, they have a price in the UK and a price in the US that aren’t based on exchange rates. If you want a price to update based on the exchange rates against a “base” currency then you’ll have to build that I’m afraid.

Activity icon

Replied to What Happens If I Canceled My Subscription?

Nothing. You just can’t use Forge to manage them and deploy any more if you don’t have a subscription.

Activity icon

Replied to Need Suggestion What To Use (API Or WEB) Next In Laravel Project?

@yanikkumar Only build an API if you actually need an API.

If all you’re wanting to do is a small number of things over AJAX, then you can return JSON responses if the request was made via AJAX:

class PostLikeController extends Controller
{
    public function store(Request $request, Post $post)
    {
        $request->user()->like($post);

        if ($request->expectsJson()) {
            return response()->json(null, 204);
        }

        return redirect()
            ->route('post.show', compact('post'))
            ->with('success', __('Post was liked.'));
    }
}