martinbean

martinbean

Member Since 4 Years Ago

Newcastle upon Tyne, UK

Senior Developer at Visualsoft Ltd

Experience Points 497,695
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 488
Lessons
Completed
Best Reply Awards 675
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

16 Jul
6 days 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.

15 Jul
1 week ago

martinbean left a reply on Mocking 3rd Party Classes Within Singleton

@jamesfreeman Dont mock what you dont own.

If its a third-party class, its developer should be testing it. You need to write an integration test that tests your application behaves as expected when using this third-party package and its public API (public methods). You shouldnt be testing the internals of someone elses code.

martinbean left a reply on Mocking 3rd Party Classes Within Singleton

@jamesfreeman That seems to be awfully low level. If you really need to check a class is instantiated with specific configuration values, you could make accessors and check them against the expected config values:

$instance = $this->app->make(TwitterOAuth::class);

$this->assertSame($instance->getConsumerKey(), config('twitter.consumer_key'));
$this->assertSame($instance->getConsumerSecret(), config('twitter.consumer_secret'));
// and so on

But yeah, seems very low-level.

martinbean left a reply on Creating An E-Commerce Website On Laravel

@simant Can you stop spamming the forum, please?

martinbean left a reply on Call Controller Function From Another Controller

basically after saving my $Request to a particular table, i want to take a particular field of $Request and decode it and store the result in another table.

@lukegalea16 Still doesnt seem to appropriate to be calling one controller action inside another.

Instead, maybe raise an event when a request is stored so a listener can take the property value and do what it needs to with it.

martinbean left a reply on Mocking 3rd Party Classes Within Singleton

@jamesfreeman Im not sure what it is youre trying to test. That the Twitter class is instantiated with the expected configuration values, or that retrieving Tweets pulls them from the cache if theyve already been cached?

13 Jul
1 week ago

martinbean left a reply on Doubt On How To Define Model For Team-Athletes-Sports Relationsships

@hachimaki I think you might need to create a custom pivot model, that has a relationship to the Sport model:

class AthleteTeam extends Pivot
{
    public function sport()
    {
        return $this->belongsTo(Sport::class);
    }
}
foreach ($team->athletes as $athlete) {
    return $athlete->sport->name;
}
12 Jul
1 week ago

martinbean left a reply on Doubt On How To Define Model For Team-Athletes-Sports Relationsships

@hachimaki Yeah, add sport_id as a column on your athlete_team pivot table then if a team can have athletes that each may play a different sport for that team.

If an athlete can only play a sport for a single team, then you can put a unique key on the athlete_id and sport_id columns:

// Will only allow athlete to play a particular sport for one team only
$table->unique(['athlete_id', 'sport_id']);

martinbean left a reply on Send Sms Free From Laravel Application

10k text per month for 20e per month

@aurawindsurfing not free ;)

martinbean left a reply on Doubt On How To Define Model For Team-Athletes-Sports Relationsships

@hachimaki Yeah, but what @mstrauss is suggestion makes sense as well.

Does a team play one sport? Or can atheletes on the same team play multiple sports? If a team only plays one sport (i.e. is a football team, or a basketball team, etc) then it makes more sense for the Team to be related to the Sport model. Then any athletes assigned to that team are inferred to play whatever sport that team plays.

11 Jul
1 week ago

martinbean left a reply on Doubt On How To Define Model For Team-Athletes-Sports Relationsships

@hachimaki Yes. Youd query the Teams athletes relation. Youd get each athletes sport in the pivot data.

martinbean left a reply on Doubt On How To Define Model For Team-Athletes-Sports Relationsships

@hachimaki I think, in the pivot table where you assign an athlete to a team, you maybe define the sport there:

Schema::create('athlete_team', function () {
    $table->unsignedInteger('athlete_id');
    $table->unsignedInteger('team_id');
    $table->unsignedInteger('sport_id');
});

Youll then be able to see what sport an athlete plays for each team.

martinbean left a reply on Laravel SSO With Passport And Socialite

@hugo411 We might be able to help if you tell us what errors youre getting.

04 Jul
2 weeks ago

martinbean left a reply on Synchronous Vs Asynchronous

@rohail12 Asynchronous basically means as well as. Its something that happens at the same time as something else, rather that waiting for one task to finish before moving on to another.

01 Jul
3 weeks ago

martinbean left a reply on Any Global Payment Systems Out There?

@falloutboi Probably not.

Different countries support different cards. The support for cards will vary wildly between the continents of Europe and Asia.

Youll also be hard-pressed to find something thats just going to take the money from someones card and deposit it in your own, checking/current account. Most payment processors (such as Stripe, which I linked you to in your last post) will have a merchant account, from which you can withdraw funds.

martinbean left a reply on Capture Exec Output

@uicreative Use shell_exec instead. It returns the output.

$output = shell_exec('your command');

martinbean left a reply on Embedded Youtube Video Keep Playing After Closing Modal

@nhayder Youll need to pause the video when you hide the modal, because the modal (and its children) is still on the page, its just not visible.

30 Jun
3 weeks ago

martinbean left a reply on Payment System?

@falloutboi Cashier uses Stripe, which supports many payment methods, including MasterCard and Visa.

28 Jun
3 weeks ago

martinbean left a reply on .

Great topic. Would read again.

25 Jun
3 weeks ago

martinbean left a reply on Regarding Video Integration

@deekshith Again, you should set the src parameter of the iframe to the Vimeo player URL, and not a URL in your domain.

24 Jun
4 weeks ago

martinbean left a reply on Regarding Video Integration

@deekshith If you’re trying to do something similar to Laracasts, then you’ll need to restrict the domains that the video can play back on. That way, even if someone does add the iframe to their website, the video will not play.

See the “Enabling domain-level privacy” section here: https://vimeo.zendesk.com/hc/en-us/articles/224819527-Changing-the-privacy-settings-of-your-videos

21 Jun
1 month ago

martinbean left a reply on What Is The Best Practice For Building Seperate Login For User And Admin In Laravel 5.7 +

@jinsonjose A login form is a login form.

You should have a single user model, and then use authorization to determine what a user can and cannot do in your application.

19 Jun
1 month ago

martinbean left a reply on Controller/Route Design For "frontend Updating"

@oliverbusk The advice from @aurawindsurfing is good. As Adam says, a “resource” in your application doesn’t have to have a corresponding Eloquent model and/or database table.

So in your example of “changeDPI”, you’re merely updating the DPI or an Image resource, so you could model that route as:

Route::put('images/{image}/dpi', '[email protected]');

The same with optimisations. If you’re applying an optimisation to an image, then you could have another nested resource controller for image optimisations:

Route::post('images/{image}/optimisations', '[email protected]');

Each new optimisation is a POST request to that image’s nested optimisation controller.

17 Jun
1 month ago

martinbean left a reply on Sorry, Please Ignore - First Discussion Post - Testing...

@dactex What exactly were you “testing”? :-/

10 Jun
1 month ago

martinbean left a reply on Picking Up Implicit Model In Middleware

@bwrigley If your route parameter is {forum_thread} then you can get what’s bound to it in a middleware class like this:

$thread = $request->route('forum_thread');
07 Jun
1 month ago

martinbean left a reply on Di Outside Of Controller?

@6acypman Dependency injection works in any class resolved by the service container. The same for methods.

Dependency injection works in controller actions because controller actions are resolved by the container when routing.

05 Jun
1 month ago

martinbean left a reply on Interfaces Again

@MINDEXPERIMENT - @mindexperiment No problem at all! Happy to help :)

04 Jun
1 month ago

martinbean left a reply on Ideas For Implementing Customer-levels

@REACHED - @reached So it sounds like campaigns have eligibility criteria.

In that case, each user could have a “value” against them, and then you can have a Level model that represents the threshold for that level.

$user = User::create(['name' => 'John Doe', 'value' => 300]);
$gold = Level::create(['name' => 'Gold', 'threshold' => 250]);
$platinum = Level::create(['Platinum' => 'Platinum', 'threshold' => 500]);
$diamond = Level::create(['name' => 'Diamond', 'threshold' => 1000]);

Given the above, John Doe (a user with a value of 300) would fall within the Platinum level (as his value is over Gold’s threshold of 250, but less than Platinum’s threshold of 500).

You can then link a Campaign to a Level, and display eligible campaigns to the user like this:

// Only fetch campaigns that have a level with a threshold greater than the user’s current value
$campaigns = Campaign::whereHas('level', function ($level) use ($user) {
    return $level->threshold > $user->value;
})->get();

martinbean left a reply on Ideas For Implementing Customer-levels

@reached What is an example of a “level”? How does a level affect campaigns? As your customer–campaign relationship is simply a one-to-one, but knowing more about what a “level” is an how it works may change the relationship.

martinbean left a reply on Interfaces Again

@MINDEXPERIMENT - @mindexperiment No problem. I get what you’re trying to do (polymorphism) and it’s absolutely the right way to go with comments.

Unfortunately, when it comes to routing, you’ll need to somehow tell Laravel what model type it is you’re adding a comment on. One approach (which I prefer) it a “nested resources”, where each “comment-able” model has its own corresponding comment controller, i.e. ArticleCommentController. However, they can all just delegate to the same method to actually create the comment:

ArticleCommentController extends Controller
{
    public function store(StoreCommentRequest $request, Article $article)
    {
        $request->user()->commentOn($article, $request->input('comment_text'));
    }
}
EventCommentController extends Controller
{
    public function store(StoreCommentRequest $request, Event $event)
    {
        $request->user()->commentOn($event, $request->input('comment_text'));
    }
}
ProductCommentController extends Controller
{
    public function store(StoreCommentRequest $request, Product $product)
    {
        $request->user()->commentOn($product, $request->input('comment_text'));
    }
}
class User extends Model
{
    public function commentOn(Commentable $model, string $text)
    {
        return $this->comments()->create([
            'text' => $text,
        ]);
    }
}
03 Jun
1 month ago

martinbean left a reply on Interfaces Again

@mindexperiment Yes. How else are you expecting Laravel to know what model you’re leaving a comment on?

In your example…

public function comment(Request $request, SubjectInterface $subject);

…just what exactly are you expecting the corresponding route to look like? How are you going to tell Laravel what model type and its ID through a single parameter?

martinbean left a reply on Interfaces Again

@mindexperiment Again, you’re type-hinting an interface.

If you have multiple classes implementing SubjectInterface, how is Laravel supposed to know which one you want to inject?

You can’t do what you’re trying to do. I get you’re trying to DRY your code out, but Laravel just isn’t able to read minds. You can’t type-hint an interface that can have multiple concrete implementations and expect Laravel to know which one you want.

Instead, you need to type-hint a concrete implementation in your controllers:

class ArticleCommentController extends Controller
{
    public function store(StoreCommentRequest $request, Article $article)
    {
        // $article can implement SubjectInterface

        // comment method should type-hint SubjectInterface

        $request->user()->comment($request->all(), $article);
    }
}
31 May
1 month ago

martinbean left a reply on Brownfield Testing

@chrisebner It depends on the time and budget you have.

If I inherit a legacy project and want to change some code, I’ll usually write a test for the code in its current condition. I’ll then re-factor, using the test to ensure I’m not breaking anything.

The key to re-factoring is small changes. If you’re only changing small amounts of code at a time, then that makes writing tests around those portions of code easier.

29 May
1 month ago

martinbean left a reply on Where Should Basic Logic Be Placed?

IP Blocking

@learn-by-flying This is intercepting a HTTP request and doing something if a condition isn’t met, which makes it a perfect candidate for middleware.

You could create a class that checks the IP address of the user and redirects if it’s not in your whitelist:

class VerifyUserIsUsingVpn
{
    public function handle($request, Closure $next)
    {
        $ipAddressOfVpn = '123.123.123.123';

        if ($request->ip() === $ipAddressOfVpn) {
            return $next($request);
        }

        return redirect()->to('url-containing-connection-instructions');
    }
}

Is there a way to define some master global variables for the entire framework?

I’m guessing you’re using to have a file you include with a load of variables/constants. Instead, you can organise your “global” variables into configuration files.

Without knowing what “global” variables you are wanting to set, I can’t really give an example.

28 May
1 month ago

martinbean left a reply on Best Schema For Comments Table Which Has Users And Visitors Comments

i see the current approach is kinda not good

@ahmedsami Why so?

16 May
2 months ago

martinbean left a reply on Testing Gate Policies

@chrisblackwell If you look at a policy, they’re just plain ol’ PHP classes (“POPOs”), so you can just test their methods by passing a user and a model under test:

class ArticlePolicyTest extends TestCase
{
    use RefreshDatabase;

    protected $policy;

    protected function setUp()
    {
        parent::setUp();

        $this->policy = new ArticlePolicy;
    }

    public function testUpdate()
    {
        $user = factory(User::class)->create();
        $article = factory(Article::class)->create();

        // Assert whether user should or should not be able to update article
        $this->assertFalse($this->policy->update($user, $article));
    }
}
14 May
2 months ago

martinbean left a reply on In Axios Request I Got Has Been Blocked By CORS Policy Error

@mstdmstd The resource at example.com:9090/searchWeb needs to add the Access-Control-Allow-Origin header with the value of the domain where /website-blogs is hosted.

13 May
2 months ago

martinbean left a reply on PHP Vs Python- Which Is The Best Programming Language For Development?

@judi Given this is your first post on a PHP-related forum, I’m going to guess you’re trolling.