martinbean

Technical Lead at Pfizer

Member Since 6 Years Ago

Newcastle upon Tyne, UK

Experience Points
757,365
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
596
Lessons
Completed
Best Reply Awards
1015
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
757,365 XP
Jun
11
2 days ago
Activity icon

Replied to Parameter Not Required In __construct Of API Resource

@sinres Don’t override core framework files like this.

Resource classes are meant to prepare an existing model for a response. You shouldn’t need to pass additional parameters like that.

Activity icon

Replied to Looking For A Template For React

@demonz Wow, waited less than a day before bumping with a passive-aggressive reply…

I imagine no one replied because no one really wanted to put effort into answering a question you had put little effort in to.

What exactly are you looking for in a “template”? React is just a JavaScript library. Install it using NPM, then start writing your components.

https://laravel.com/docs/8.x/mix#react

Activity icon

Replied to How To Block Laravel_session And XSRF-TOKEN Cookies Until The User Accepts/allow It In Laravel 5.8

Indeed. You can use session cookies without consent. The pertinent part from that article:

Strictly necessary cookies — These cookies are essential for you to browse the website and use its features, such as accessing secure areas of the site. Cookies that allow web shops to hold your items in your cart while you are shopping online are an example of strictly necessary cookies. These cookies will generally be first-party session cookies. While it is not required to obtain consent for these cookies, what they do and why they are necessary should be explained to the user.

Consent is required for analytics and advertising tracking cookies, though. And they should at no point contain personally-identifiable information (such as name, email address, etc).

Jun
10
3 days ago
Activity icon

Replied to Binary In Blade Template Javascript?

@waffl Responses (typically) use UTF-8 encoding, so you can’t send binary data in a response like that. You’ll need to convert it to a UTF-8 compatible format.

Activity icon

Replied to Stripe Payment With Laravel

Yes. We’ve got that. Now try answering the questions I actually asked you.

What is the business reason for spreading the payments over five minutes? Seems a bit pointless to me.

Activity icon

Replied to Do Request Validators Deprecate The Need For Unit Tests?

I mean, you have the validators in place, you send your request that confirms there are no errors. Is there still any reason to test the underlying implementation details that produced the response behind this request?

I covered this in my previous response…?

I'm asking this considering the fact that those unit methods, will ultimately be tested by passing in payloads/data/arguments that, in real life, would've failed if they went through an organic request and its validator. Is it clearer now?

Not really. Validation != testing. You should validate all request data. But you don‘t know your validation is working, or deviates from a working state, unless you’re testing it.

Activity icon

Replied to Stripe Payment With Laravel

Why? Why after 5 minutes? Why not just charge the full amount? Why are they split into two payments five minutes apart?

Activity icon

Replied to Do Request Validators Deprecate The Need For Unit Tests?

@nmeri17 You’re right in that unit tests test a piece of code in isolation by providing inputs and asserting the outputs, but wrong in that just because you have validation in your application you no longer need to test. How do you know your validation’s working if you don’t have tests…?

With validation, I don‘t unit test the validators or form request themselves. I’ll have feature tests where I say, interact with the endpoint. I’ll provide data and either assert I get a successful response or validation errors depending on the scenario I’m testing. The feature test will by its nature cover the validator/form request. When am I ever going to use the form request outside of a controller action? I’m not.

I’ll test both successful cases as well as any common failure cases. Required fields is a common one, so I’ll use data providers to test that a validation error is present if I omit a field that’s required:

/**
 * @dataProvider requiredFieldsDataProvider
 */
public function testFieldIsRequired(string $field): void
{
    $data = [
        'headline' => 'Test Headline',
        'summary' => 'Test article summary.',
        'body' => 'Test article body.',
    ];

    Arr::remove($data, $field);

    $this
        ->post('/articles', $data)
        ->assertSessionHasErrors($field);
}

public function requiredFieldsDataProvider(): array
{
    return [
        'headline' => ['headline'],
        'summary' => ['summary'],
        'body' => ['body'],
    ];
}

So now I have a test that covers all of my required validation rules for creating an article. If I omit a field that should be required but don’t get a validation failure (because I’ve messed up my form request some how) then I’ll get a failing test.

Similarly I’ll have a “positive” test case:

public function testCanCreateArticleWithValidData(string $field): void
{
    $data = [
        'headline' => 'Test Headline',
        'summary' => 'Test article summary.',
        'body' => 'Test article body.',
    ];

    $this
        ->post('/articles', $data)
        ->assertSessionHasNoErrors();

    $this->assertDatabaseHas('articles', [
        'headline' => 'Test Headline',
        'summary' => 'Test article summary.',
        'body' => 'Test article body.',
    ]);
}

Again, if this fails (because I’ve messed up my validation, added rules, or whatever) then the test will also fail, leading me to either fix the issue if there is one, or update the test to reflect any new validation.

Activity icon

Replied to Testing My Repository

@fioreski It sounds like you may have erroneously set the namespace in your class. It should be:

namespace App\Repository;

Pay attention to the casing. The namespace should also follow your directory structure. So the class App\Repository\BaseRepository should be found at the path app/Repository/BaseRepository.php

Activity icon

Replied to Stripe Payment With Laravel

@doncho85 Why are you randomly charging a user again after 5 minutes?

Activity icon

Replied to Testing My Repository

@fioreski So a couple of issues I can see:

You have this import:

use app\Repository\BaseRepository\BaseRepository;

Is that right? The App namespace (and all namespaces) should start with a capital letter. And do you really have a class named BaseRepository in a directory also called BaseRepository?

Also, this isn’t a unit test. You‘re not testing a single unit of code here. You’re inserting a model into a database and then testing how your code interacts with that data in the database, so you’re not testing in isolation here.

A unit test should be able to be ran without touching anything else—so it shouldn’t need a database nor the framework. You should be able to execute a single a single piece of code, use mocking for any parameters you need to mock, and be able to assert the response without it touching other classes, resources like databases and queues, etc.

Activity icon

Replied to Testing My Repository

Put three back-ticks ( ` ) before and after your code sample.

Activity icon

Replied to Making P2P Applications Multilingual

@fahaddsheikh If it’s a quiz app then I assume there are questions, and then options (answers). So each question and answer option would have multiple translations.

When you deliver a question to the end users, you can then pick the translation that matches their locale preference. You’ll need to decide what to do if there isn‘t a translation for the locale they’ve picked though, i.e. if I’ve set my locale to Brazilian Portuguese but the question or answers don’t have a translation available for that locale.

Activity icon

Replied to Auto Locale Detect

@chris1989 Then do that?

Write some middleware that gets the locale from the request and sets the configuration value for that request:

class SetLocaleFromRequest
{
    public function handle(Request $request, Closure $next)
    {
        config([
            'app.locale' => $request->getLocale(),
        ]);

        return $next($request);
    }
}

If you need to normalise the locale value, then you need to normalise it. So if you get a locale with additional data, but you only want the first part (en), then split it on the first underscore:

config([
    'app.locale' => Str::before($request->getLocale(), '_'),
]);
Jun
09
4 days ago
Activity icon

Replied to How To Add Extra Column To Session Table And How To Store Data In It?

@bobzamin You’re using the session completely wrong. Just store whatever data you need in the session itself.

Activity icon

Awarded Best Reply on Testing Laravel Apps Practices

Do you write tests for small web apps or only for mid/large systems?

@bor1904 Why do you think you would only write tests for “mid” or “large” systems? Is a “small” app not worthy of being tested? Do you not care if a “small” app works or not?

Testing is exactly that: testing something works. It makes no claims about how “big” an app has to be before it warrants testing. You write tests if you want to be sure the code you’re writing works, and you omit them if you’re not bothered.

Always phpunit or always dusk? Or it depends?

Personally, PHPUnit-based tests. I’ll write feature tests that essentially make HTTP requests and then make assertions on the responses, i.e. whether I’m expecting a successful response or say, validation errors if I intentionally submit incorrect data.

I’ll then create another tests/Integration directory and put tests in their that test the actual classes of my application. So things like service classes, jobs, etc. Classes that I can test together but without invoking them through a HTTP request or CLI command.

I write very little unit tests as I find feature and integration tests give me enough coverage. I also can’t remember the last time I used Dusk. I’d maybe use it if I was doing a lot of UI-heavy work, but find it slow and would probably use something else for automated browser testing like Cypress if I needed to do these types of tests.

Do you develop your projects in TDD or usually you write test after coding?

TDD is nice, but never works in practice for me. It can work for feature tests where you know you want an endpoint to receive some data and return a particular response and then you can use your test to drive the implementation, but I find it impossible to do TDD at the unit level, as you kinda need to already know the code you’re writing ahead of time to be able to write granular tests like that.

So I’ll add tests as I code. I’ll get something working, as I may go through several iterations of renaming things the more code I write. Once I get something tangible (i.e. a controller action that does something) then I’ll write a test for that.

You normaly cover whole app by tests or only critical area/flow?

I cover the parts I need covered and want to be confident work. Too many people chase 100% code coverage but then you ended up testing useless things like the HTTP kernel class or form request classes, and end up with tests for the sake of tests. Why are you ever going to use a form request classes on its own? You wouldn’t. So its logic would be covered by the feature test for the controller that makes use of it. That request class is then covered by that test; no need to write a separate “unit” test for that form request class.

As mentioned above, I’ll also test validation by intentionally passing invalid data to endpoints. So omitting fields that are required, passing out-of-range values for things like min and max rules, etc. This can obviously get laborious quickly, so you can use PHPUnit data providers to simplify these tests:

public function testFieldIsRequired(string $field): void
{
        $data = [
            'headline' => 'Test Headline',
            'summary' => 'Test summary.',
            'body' => 'Test body.',
        ];

        // Remove the required field
        Arr::forget($data, $field);

        $response = $this->post('/articles', $data);

        // Assert validation failure for given field
        $response-> assertSessionHasErrors($field);
}

public function requiredFieldsDataProvider(): array
{
    return [
        'headline' => ['headline'],
        'summary' => ['summary'],
        'body' => ['body'],
    ];
}

Do you write unit or future tests more often? Or always both?

I pretty much covered this above.

I start long project In small team and havent too mach practical knowladge about todays best practices in this area.

The crux is, you can get quite far with feature tests. Start with feature tests, make HTTP requests to your application and then assert the side effects. Check models were created that you expect to be created; check expected validation errors are thrown when you submit intentionally bad data; test queue jobs and mails are dispatched if they need be. This will quickly give you a lot of coverage and confidence in your applications. If you’re writing complicated business logic with lots of classes, you can then drop down to writing integration or unit tests that cover these classes in isolation.

Activity icon

Replied to Queue (dispatchSync) Response

@pokeycam If you’re dispatching a job synchronously, then that will return whatever the job’s handle method returns.

class JobThatDoesApiRequest
{
    public function handle()
    {
        $response = Http::get('http://example.com');

        return $response->json();
    }
}
$response = Queue::dispatchSync(JobThatDoesApiRequest::class);
Activity icon

Replied to Larvel.build

@ady_gould I’m not sure I really understand what it is you’re asking for, but the source code for the Sail package is on GitHub: https://github.com/laravel/sail

Activity icon

Awarded Best Reply on Any Way To Login Web Guard Using An API Request?

An API is stateless. Retrieving a token from an API shouldn’t then be creating state (a session) on that server.

Instead, you can use the appropriate OAuth grant type. If your customer wants the user to be logged in then you should use the typical authorization code flow. The user will be redirected to the API server to log in with their account on that server. When they log in, they’ll then be redirected back to your WordPress site with an authorization code and your WordPress site can then use that code to get an access token for that user. The user will also be logged in on the other server because they would have had to log in to authorize the request.

Activity icon

Replied to Any Way To Login Web Guard Using An API Request?

An API is stateless. Retrieving a token from an API shouldn’t then be creating state (a session) on that server.

Instead, you can use the appropriate OAuth grant type. If your customer wants the user to be logged in then you should use the typical authorization code flow. The user will be redirected to the API server to log in with their account on that server. When they log in, they’ll then be redirected back to your WordPress site with an authorization code and your WordPress site can then use that code to get an access token for that user. The user will also be logged in on the other server because they would have had to log in to authorize the request.

Activity icon

Replied to How To Read .mov Metadata

@dokolenko24cm Have you tried Google…?

Activity icon

Replied to Use VueRouter In Laravel

@roughlik Because you haven’t actually defined any routes from what I can see.

Activity icon

Awarded Best Reply on Stripe, Register User On Successful Payment

@gavmrz On the flip side, if you attempt to register them after a payment but they’ve already signed up, then you’re going to get a situation where you’ve charged the customer, but then the customer will get an error message saying something like, “Sorry, this email has already been taken”.

If you have a two-step flow like this, you’d normally create the account on the first step. You can then send an email to the customer notifying them they’ve registered whilst they’re making payment. If they abandon this step, they still have an account (and an email telling them their account was created). So you can include a link in this email saying something along the lines of “Your account has been created. Please complete payment”.

Activity icon

Replied to Stripe, Register User On Successful Payment

@gavmrz On the flip side, if you attempt to register them after a payment but they’ve already signed up, then you’re going to get a situation where you’ve charged the customer, but then the customer will get an error message saying something like, “Sorry, this email has already been taken”.

If you have a two-step flow like this, you’d normally create the account on the first step. You can then send an email to the customer notifying them they’ve registered whilst they’re making payment. If they abandon this step, they still have an account (and an email telling them their account was created). So you can include a link in this email saying something along the lines of “Your account has been created. Please complete payment”.

Activity icon

Replied to Testing Laravel Apps Practices

Do you write tests for small web apps or only for mid/large systems?

@bor1904 Why do you think you would only write tests for “mid” or “large” systems? Is a “small” app not worthy of being tested? Do you not care if a “small” app works or not?

Testing is exactly that: testing something works. It makes no claims about how “big” an app has to be before it warrants testing. You write tests if you want to be sure the code you’re writing works, and you omit them if you’re not bothered.

Always phpunit or always dusk? Or it depends?

Personally, PHPUnit-based tests. I’ll write feature tests that essentially make HTTP requests and then make assertions on the responses, i.e. whether I’m expecting a successful response or say, validation errors if I intentionally submit incorrect data.

I’ll then create another tests/Integration directory and put tests in their that test the actual classes of my application. So things like service classes, jobs, etc. Classes that I can test together but without invoking them through a HTTP request or CLI command.

I write very little unit tests as I find feature and integration tests give me enough coverage. I also can’t remember the last time I used Dusk. I’d maybe use it if I was doing a lot of UI-heavy work, but find it slow and would probably use something else for automated browser testing like Cypress if I needed to do these types of tests.

Do you develop your projects in TDD or usually you write test after coding?

TDD is nice, but never works in practice for me. It can work for feature tests where you know you want an endpoint to receive some data and return a particular response and then you can use your test to drive the implementation, but I find it impossible to do TDD at the unit level, as you kinda need to already know the code you’re writing ahead of time to be able to write granular tests like that.

So I’ll add tests as I code. I’ll get something working, as I may go through several iterations of renaming things the more code I write. Once I get something tangible (i.e. a controller action that does something) then I’ll write a test for that.

You normaly cover whole app by tests or only critical area/flow?

I cover the parts I need covered and want to be confident work. Too many people chase 100% code coverage but then you ended up testing useless things like the HTTP kernel class or form request classes, and end up with tests for the sake of tests. Why are you ever going to use a form request classes on its own? You wouldn’t. So its logic would be covered by the feature test for the controller that makes use of it. That request class is then covered by that test; no need to write a separate “unit” test for that form request class.

As mentioned above, I’ll also test validation by intentionally passing invalid data to endpoints. So omitting fields that are required, passing out-of-range values for things like min and max rules, etc. This can obviously get laborious quickly, so you can use PHPUnit data providers to simplify these tests:

public function testFieldIsRequired(string $field): void
{
        $data = [
            'headline' => 'Test Headline',
            'summary' => 'Test summary.',
            'body' => 'Test body.',
        ];

        // Remove the required field
        Arr::forget($data, $field);

        $response = $this->post('/articles', $data);

        // Assert validation failure for given field
        $response-> assertSessionHasErrors($field);
}

public function requiredFieldsDataProvider(): array
{
    return [
        'headline' => ['headline'],
        'summary' => ['summary'],
        'body' => ['body'],
    ];
}

Do you write unit or future tests more often? Or always both?

I pretty much covered this above.

I start long project In small team and havent too mach practical knowladge about todays best practices in this area.

The crux is, you can get quite far with feature tests. Start with feature tests, make HTTP requests to your application and then assert the side effects. Check models were created that you expect to be created; check expected validation errors are thrown when you submit intentionally bad data; test queue jobs and mails are dispatched if they need be. This will quickly give you a lot of coverage and confidence in your applications. If you’re writing complicated business logic with lots of classes, you can then drop down to writing integration or unit tests that cover these classes in isolation.

Jun
08
5 days ago
Activity icon

Awarded Best Reply on How To Restirct Only Logged In User In API Implementation With React

@deekshith I’m struggling to understand just what it is you’re asking.

If you’re using token-based authentication then you use that token to make API calls. There’s no “logged in” or not. You either get a successful response from the API if the token you provided was valid, or an unauthorised-like response if the token is not valid or not included in the request at all.

Activity icon

Awarded Best Reply on Injecting Request In The Controller's Constructor With Laravel 8 ?

@duddy67 Don’t. Controllers are instantiated by the framework before a request is handed, so inject the request into the methods you need them instead.

Activity icon

Replied to Problem With Sanctum Middleware

@mjtpage If you’ve applied auth:sanctum middleware to your routes, then that’s what guard Laravel will use to authenticate. There is no falling back to “regular” authentication.

The Sanctum middleware works by first checking for a session cookie. It then falls back to checking for the token. So if you’ve logged in via your web app, and then hitting your API endpoints in the browser, you’re going to be authenticated.

Activity icon

Replied to How To Restirct Only Logged In User In API Implementation With React

@deekshith I’m struggling to understand just what it is you’re asking.

If you’re using token-based authentication then you use that token to make API calls. There’s no “logged in” or not. You either get a successful response from the API if the token you provided was valid, or an unauthorised-like response if the token is not valid or not included in the request at all.

Activity icon

Replied to Injecting Request In The Controller's Constructor With Laravel 8 ?

@duddy67 Don’t. Controllers are instantiated by the framework before a request is handed, so inject the request into the methods you need them instead.

Activity icon

Awarded Best Reply on Laravel Web Site Session Expired Message

@johnw65 When you make an AJAX request, if you get an unauthenticated error then display a modal or something saying, “You’re not logged in. Please log in to continue” or something, with a link that takes them to the login page.

Activity icon

Replied to Laravel Web Site Session Expired Message

@johnw65 When you make an AJAX request, if you get an unauthenticated error then display a modal or something saying, “You’re not logged in. Please log in to continue” or something, with a link that takes them to the login page.

Activity icon

Replied to Building A Chess Game

So you decided to bump a two-year-old question to say that…?

Jun
07
6 days ago
Activity icon

Awarded Best Reply on About Object Oriented Programming (oop) Php In Laravel

@asadali007 Laravel is built using object-oriented PHP so yes, a knowledge of OOP is going to be beneficial in understanding the framework code and writing your own objects that make us of the classes and methods provided by Laravel.

Activity icon

Replied to About Object Oriented Programming (oop) Php In Laravel

@asadali007 Laravel is built using object-oriented PHP so yes, a knowledge of OOP is going to be beneficial in understanding the framework code and writing your own objects that make us of the classes and methods provided by Laravel.

Activity icon

Replied to How To Get All User's Data Using Laravel APi Resource ?

Yes. You’re completely mixing up “regular” resources and collection resources.

A collection resource should transform a collection, not a single model instance like you’re doing.

Activity icon

Replied to Best Way Of Calling Specific JavaScript Files For Particular Views

@garet What type of JavaScript files? Literally vanilla JavaScript files (i.e. edit-users.js)? Or things like Vue components that are only applicable to certain Blade views?

Activity icon

Replied to Get Nova License Info From GitHub?

You can also use an API token created in your Nova account in place of your account’s password:

composer config http-basic.nova.laravel.com ${NOVA_USERNAME} ${NOVA_API_KEY}
Activity icon

Replied to Stripe Package Issue With Live Payments

@muazzamazaz Why do you have credit card details in your request body?!

You‘re also using an ancient version of the Stripe SDK. You say you’re using ^4.4 but the latest version is 7.82.0.

Activity icon

Replied to How To Get All User's Data Using Laravel APi Resource ?

@prince69 The issue is you’re extending the wrong class. You’re using your ResourceCollection class as if it were a single resource class.

So, extend just the regular Resource class instead of ResourceCollection, and rename your resource to what it is: UserResource. Your files should then look like this:

return UserResource::collection(User::all());
class UserResource extends Resource
{
    public function toArray($request)
    {
        return [
            'first_name' => $this->first_name,
            'last_name' => $this->last_name,
            'email' => $this->email,
            date_of_birth' => $this->date_of_birth->toDateString(),
        ];
    }
}
Activity icon

Awarded Best Reply on Test Passport-Login

Because you’re meant to get OAuth tokens from your OAuth endpoints; not proxy calls with a web controller.

Laravel is used in combination with Vue and the app is also providing OAUTH for other web apps.

That’s what multiple OAuth clients are for. Create a client for your web app, and also individual clients for the other web apps. The clients then identify themselves using the client ID so you know which client issued a particular access token.

Activity icon

Replied to Test Passport-Login

Because you’re meant to get OAuth tokens from your OAuth endpoints; not proxy calls with a web controller.

Laravel is used in combination with Vue and the app is also providing OAUTH for other web apps.

That’s what multiple OAuth clients are for. Create a client for your web app, and also individual clients for the other web apps. The clients then identify themselves using the client ID so you know which client issued a particular access token.

Activity icon

Replied to Test Passport-Login

@ahoi You wouldn’t test this… because you’re using Passport completely wrong.

What is app()->handle($request) all about?

Passport is an OAuth server implementation. So either use an appropriate OAuth grant type where you don’t expose your client’s secret key, or use Sanctum instead which is literally built for authentication things like Vue front-ends.

If you wish to stick with Passport, then the most appropriate grant type would be authorization code grant with PKCE:

The Authorization Code grant with "Proof Key for Code Exchange" (PKCE) is a secure way to authenticate single page applications or native applications to access your API.

Activity icon

Awarded Best Reply on DI In Method

@drivercat Well you have two options. If your customer service requires your CustomerGetSelectOptionsTranslator (whatever that is), then you can either:

  1. Type-hint that class in your customer service’s constructor. So when your customer service class is created, Laravel will also resolve its dependencies and inject that stupidly-long-named class into it as well.

  2. If you only need CustomerGetSelectOptionsTranslator in your editCustomer method, then you’re going to have to pass an instance of it when you call that method from your controller:

$data = $this->customerService->editCustomer(
    $customer,
    $customerGetSelectOptionsTranslator
);
Jun
06
1 week ago
Activity icon

Replied to DI In Method

It's working good, but when I have a lot of classes to inject, my constructor looks very large.

@drivercat So I’m not sure what you’re expecting here? If you inject a lot of classes then yes, you’re going to have a large constructor.

In this case I have to inject CustomerGetSelectOptionsTranslator in controller's constructor and it's almost the same as №1, because I want to inject it only in methods where I really need it.

Then inject the class in the methods that need it. But you can’t just type-hint it in the method and then neglect to pass that argument when calling the method. If a method needs two parameters, then you need to pass two parameters when calling it. You can’t just type-hint a class and go, “Laravel will sort that out for me.” That’s not what dependency injection is.

About CustomerGetSelectOptionsTranslator: can you suggest a nicer naming for it? This service layer gets data for related models dropdowns of Customer model, Translator is a name of service sublayer in my project.

Why is this in a customer service? Why do you need these for creating/saving/deleting customers? Surely these are a UI concern and should be passed to your view; not something needed for a service class?

Activity icon

Replied to How To Save Facebook Video And Show Blade File In Laravel

@dostogir Do you want to maybe form this as an actual question…?

Jun
05
1 week ago
Activity icon

Replied to Schedule In Laravel

@www888 Also, your code is really inefficient. If you have a million products, that’s going to try and run the exact same UPDATE statement a million times.

Just do:

DB::table('products')->where('status', 1)->update(['tax_price' => 100]);

No need to fetch all products and loop over them.

Activity icon

Replied to Schedule In Laravel

@www888 Are you actually running your schedule…?

Activity icon

Replied to Testcase Object Expected, Array Given

@rhand https://flysystem.thephpleague.com/v1/docs/adapter/digitalocean-spaces/ ??

The DO Spaces api are compatible with those of S3, from Flysystem’s perspective this means you can use the league/flysystem-aws-s3-v3 adapter.

Activity icon

Replied to Is Laravel 'faster' Than Ruby On Rails?

I find Rails takes less development time, may be, because Rails is my personal preference.

@bappy10 Thanks for bumping a year-old thread just to say you’re faster with something you have more experience with…