martinbean

Senior Developer at MBL Solutions

Experience

407,095

559 Best Reply Awards

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

20th July, 2018

martinbean left a reply on Date Progress Bar - Laravel 5+, Bootstrap 4 • 1 day ago

@ziben69 The easiest method would be to convert the dates to Unix timestamps, and deduct the start date from both the end and current time. You’ll then be able to see how “close” the current time is to the end date.

martinbean left a reply on How To Manage, Build And Deploy Frontend Assets And Js In Laravel Packages • 1 day ago

@pvledoux Packages should provide a “dist” (compiled) version of its assets, that you bundle in your “parent” application.

martinbean left a reply on Dynamic Rate Limiting Without User Model • 1 day ago

@Koivu You’ll probably need to create a middleware class that extends Laravel’s ThrottleRequests middleware (maybe “ThrottleRequestsByTenant”, but override the resolveMaxAttempts() method to check your tenant model rather than the user model:

https://github.com/laravel/framework/blob/74252d15d8c22be664934b251c52ff3c98147740/src/Illuminate/Routing/Middleware/ThrottleRequests.php#L65-L83

martinbean left a reply on How To Manage, Build And Deploy Frontend Assets And Js In Laravel Packages • 1 day ago

@pvledoux You define your application’s dependencies in your package.json file. When deploying, run npm run prod to build your assets and include the generated files in your deployment (but ignore them from your source control repository).

martinbean left a reply on Process Jobs In Queue Strictly One After Another • 1 day ago

@AlexeyM I’ve mentioned twice now: if the first job doesn’t complete successfully, then the queue worker will keep trying to process it and won’t move onto the second job until it succeeds.

martinbean left a reply on Include Npm Package In Laravel Project • 1 day ago

@bwrigley I think you can just follow Laravel’s example, and assign the MarkerClusterer object to the window object:

window.MarkerClusterer = require('@google/markerclustererplus');

This will then allow you to use the MarkerClusterer class in subsequent scripts.

19th July, 2018

martinbean left a reply on Process Jobs In Queue Strictly One After Another • 2 days ago

@AlexeyM What? Why? The worker just pulls the first job from the queue. If it’s successful, it moves on to the next one. Why do you need access to the queue runner?

martinbean left a reply on Process Jobs In Queue Strictly One After Another • 2 days ago

@AlexeyM Well if you don’t specify a timeout or retry limit and have a single queue worker, this is how your queue will behave: your worker will keep trying to job until it succeeds, then pull the next one, and so on.

martinbean left a reply on Create Layout From Database Objects In Blade Template • 2 days ago

@finchy70 It seems you have “rows” for each operation. You could create “sub-rows” in the rightmost two-thirds that looks like this:

@foreach($operations as $operation)
    <div class="row">
        <div class="col-4">
            <h1>{{ $operation->heading }}</h1>
        </div>
        <div class="col-8">
            @foreach($operation->risks as $risk)
                <div class="row">
                    <div class="col-6">
                        <h2>{{ $risk->heading }}</h2>
                    </div>
                    <div class="col-6">
                        @foreach($risk->measures as $measure)
                            <div>
                                <p>{{ $measure->text }}</p>
                            </div>
                        @endforeach
                    </div>
                </div>
            @endforeach
        </div>
    </div>
@endforeach

martinbean left a reply on Calling Methods In Controller • 2 days ago

@skoobi No problem. Glad I could be of help :)

martinbean left a reply on Laravel 5.6 Send Email From Scheduler Script • 2 days ago

@shahzadbuckstec The view should exist at resources/views/mail/testcronjob.blade.php if it doesn’t already.

Note: mail.testcronjob means a file named testcronjob in a sub-directory called mail, and not a file named mail.testcronjob.{extension}.

martinbean left a reply on What Is This Eloquent Problem? • 2 days ago

@alihoushyaripour Did you read the error message? It’s telling you exactly what the issue is: Column 'coin' in group statement is ambiguous. That means you have more than one coin column, and you have to be explicit as to which one you want to use by also specifying the table, i.e. activities.coin.

martinbean left a reply on Include Npm Package In Laravel Project • 2 days ago

@bwrigley If you’ve installed the package, then that will give you a module that you can use in scripts. If you’re using the JavaScript files that come with a default Laravel application then you don’t need to add it to your Webpack file. Instead, pull the module into your resources/assets/js/app.js file:

require('./bootstrap');

require('@google/markerclustererplus');

This will pull in whatever is defined as the default export of the @google/markerclustererplus module. It might also be worth reading up on JavaScript modules, too.

18th July, 2018

martinbean left a reply on Several Laravel Sites With A Shared ORM • 3 days ago

Is there a recommended method of consuming the API from a Laravel app?

@rwashingtonTA There’s lots of ways. Guzzle’s the de facto choice for executing HTTP requests.

martinbean left a reply on Restfull Laravel Good Pratice Single Or Multi Requests • 3 days ago

@jayson It’s probably better to send one payload that contains a question and its answers. Sending a question and its answers as individual requests may lead to data inconsistency (i.e. question saved, and only some answers saved because of validation errors, or an error because the question failed to save and then trying to save each answer throws an error because the parent question doesn’t exist).

Laravel validation does support validating arrays. If you have a question with multiple answers, and each answer requires a value, then you could validate that like this:

'answers' => 'required|array|min:1',
'answers.*.name' => 'required|distinct|string',

You’ll then get error messages back in a similar format so you can show errors for specific answers against that particular answer.

martinbean left a reply on Calling Methods In Controller • 3 days ago

@skoobi You would have the job class that transfers a single user, so you could execute it in a loop with the progress bar, as you are doing now:

$users = User::all();

$bar = $this->output->createProgressBar($users->count());

foreach ($users as $user) {
    // Dispatch job to transfer a single user here

    $bar->advance();
}

$bar->clear();

$this->info('Users transferred.');

martinbean left a reply on Calling Methods In Controller • 3 days ago

@skoobi You should not be calling controller methods in a console command. Controllers live in the app/Http directory for a reason: they supposed to be called in a HTTP context only, and not from the command line.

Instead, move the logic for migrating users to a job class. You can then dispatch the job from both a console command and a controller action if need be.

martinbean left a reply on Help To Seperate Backend And Frontend In Laravel • 3 days ago

@techyad Laravel doesn’t have this separation because not every application has a “front” and ”back”. Some only have one “end”, some have more than two.

For example, I run a video on demand service which has the public-facing website, an area for channel owners to upload videos, and then an administration system for me to manage everything on the site. There’s three “ends”.

There’s nothing stopping you having sub-directories. If you have an administration panel in your Laravel application that’s your “back-end”, then you might have your front-end controllers under app/Http/Controllers, and then a app/Http/Controllers/Admin directory for your admin panel controllers.

17th July, 2018

martinbean left a reply on Several Laravel Sites With A Shared ORM • 4 days ago

@rwashingtonTA Sharing models between multiple Laravel applications via a package just makes for a headache as every time you change a model, you then have to run composer update in all the applications using those models.

Instead, have one “core” application that has the models (and database connection), and expose its data via an API to the other, consuming applications.

martinbean left a reply on Route 53 And Heroku • 4 days ago

@mick79 You need to set up an “alias” record for the apex (root).

16th July, 2018

martinbean left a reply on Eloquent, Make Items Upgradable • 5 days ago

So now can i bump?

@Stank0V01 Why do you think your thread is more important than any one else’s?

14th July, 2018

martinbean left a reply on Union/Join/Merge Table To Get The Result • 1 week ago

@ravipw1801 Please don’t tag me to get me to read your question. I answer questions as and when I can.

13th July, 2018

martinbean left a reply on Multiple Search Refinements On Controller • 1 week ago

@JamesFreeman Nope. You saw an opportunity to re-factor and took it, that’s good :)

There’s a Laracasts lesson that covers exactly this, where Jeffrey extracts “filters” to a class like you have done: https://laracasts.com/series/eloquent-techniques/episodes/4

martinbean left a reply on Eloquent Relationship: Garage - Car - Security • 1 week ago

@ChibiSaru What does your Security model represent?

martinbean left a reply on Debugging VueJS Error Messages • 1 week ago

@mathewparet “1:130” usually means line 1, column 130.

12th July, 2018

martinbean left a reply on Relations • 1 week ago

@Aetrox A device would have many attributes, so that means your attributes table would have a device_id foreign key:

Schema::create('devices', function (Blueprint $table) {
    $table->increments('id');
    $table->string('serial_number')->unique();
    $table->timestamps();
});

Schema::create('attributes', function (Blueprint $table) {
    $table->increments('id');
    $table->unsignedInteger('device_id');
    $table->string('name');
    $table->string('value');
    $table->timestamps();
    $table->foreign('device_id')->references('id')->on('devices')->onDelete('cascade');
    
    // Stops a single device having multiple attributes with the same name
    $table->unique(['device_id', 'name']);
});

martinbean left a reply on Relations • 1 week ago

@Aetrox No. Attributes would be key–value pairs. So attributes would have name and value columns. The name may be colour and the value red.

martinbean left a reply on Default Cache Time In Laravel? • 1 week ago

@thebigk 60 minutes (https://github.com/laravel/framework/blob/5.6/src/Illuminate/Cache/Repository.php#L44-L49), but you should be explicitly defining how long you want to store an item.

martinbean left a reply on Relations • 1 week ago

@Aetrox I’d say you have users that have many devices, and a device has many attributes. An attribute would be key–value pairs for things like colour, storage capacity etc. Serial number sounds pretty standard, so I’d be tempted to move that to the Device model.

11th July, 2018

martinbean left a reply on Embed Images In Markdown Emails • 1 week ago

@Tappad Have you tried the Markdown syntax for an image? https://daringfireball.net/projects/markdown/syntax#img

martinbean left a reply on Desperate For Ideas On Possible Design Patterns • 1 week ago

@cr0nwell It seems the Strategy pattern would be a good candidate. If you have different providers with websites marked up in different ways, then you can create a strategy class for each website that pulls the product data from the relevant parts of the web page.

“Scraping” a new website then just means creating a new strategy class and if a website updates their mark-up, the changes are limited to one class.

Some pseudo-code:

foreach ($websites as $website) {
    $strategy = $website->getScrapingStrategy();

    $products = $strategy->getProducts();

    foreach ($products as $product) {
        // Methods to access product name, price etc.
    }
}

martinbean left a reply on Snake_case Or CamelCase • 1 week ago

@mboothemerald Why have you commented on a three-year-old discussion…?

martinbean left a reply on Custom Authentification Query • 1 week ago

@victordbu The name column should contain unique values only. Authentication mechanisms should not rely on the order rows are stored in a database table.

martinbean left a reply on Laravel Or Lumen? What To Use? • 1 week ago

@Bartude I’d say just go with Laravel.

Lumen is essentially a stripped-down version of Laravel, so you could just comment-out/remove providers from your config/app.php file that you don’t need.

martinbean left a reply on Comment And Reply • 1 week ago

@ARTHURSTABRIGIDA It wouldn’t be a recursive relationship, but a comment in reply to another comment would hold the ID to a parent comment. So your Comment model would have two relationships: parent and children:

class Comment
{
    public function parent()
    {
        // Will return null if comment is top-level comment
        return $this->belongsTo(Comment::class, 'parent_id');
    }

    public function children()
    {
        // Returns any replies to this comment
        return $this->hasMany(Comment::class, 'parent_id');
    }
}

martinbean left a reply on Store Image In Database • 1 week ago

@Mike_3096 Have you read the error message. It’s telling you the problem: Unknown column 'updated_at'.

Looking at your migration, you could probably do with reading the Laravel documentation on how to create columns, rather than trying to create them using raw SQL statements: https://laravel.com/docs/master/migrations#columns

martinbean left a reply on Vue Authentication Best Practice. • 1 week ago

@eng.helewa We can’t really suggest what to do as we don’t know how you’ve developed your application, and how much you’ve “Vue-ified” it.

When developing components, I’ll have them responsible for fetching the data they need to display and then render the data when ready.

I’d suggest reading the Passport documentation, as that covers authenticating requests from the front-end. There may be something in there you can use as inspiration/a basis for your own implementation.

martinbean left a reply on Vue Authentication Best Practice. • 1 week ago

at any time during the loading and before redirecting the user you can hit the Escape button, open the dev-tools and start playing with the protected area of the application.

@eng.helewa Then make sure you’er not displaying anything sensitive, and authorising all API calls. You should be fetching data via API endpoints, too.

martinbean left a reply on How To Make A Grid In Laravel • 1 week ago

@armancs The “proper answer” you’re looking for is in the publicly-available Laravel documentation: https://laravel.com/docs/master/blade#defining-a-layout

martinbean left a reply on I Dont Want Bootstrap 4 With Laravel 5.6 !!! • 1 week ago

@AsnCode

npm uninstall bootstrap popper.js --save-dev
npm install bootstrap-sass --save-dev

martinbean left a reply on Laravel Echo And Heroku • 1 week ago

@Thorgram I don’t think a free Heroku dyno is going to cut it, as it sleeps after a period of inactivity, and you only get so many free dyno hours a month.

martinbean left a reply on Redirecting Back On Validation Error Instead Of 422 JSON • 1 week ago

@mkdesign82 If you want validation errors as JSON, then you need to send the request as JSON.

martinbean left a reply on Vue Authentication Best Practice. • 1 week ago

@eng.helewa Maybe look at putting a “loading” state in your components.

When a component is mounted, show the loading state whilst checking the access token and then display the appropriate component (error or dashboard) depending on if the token is valid or not.

martinbean left a reply on Stripe Connect Tutorial • 1 week ago

@shifoodew You will need to set a redirect URL in Stripe. Stripe will redirect back to this URL after a user has authorised your application. In this redirect URL you need to execute this POST request: https://stripe.com/docs/connect/oauth-reference#post-token

You can use something like Guzzle to do this. In the response, you’ll then get the connected account’s ID, access token etc.

10th July, 2018

martinbean left a reply on PHP Quivalent Of This JS Code • 1 week ago

@samalapsy Sorry, but this isn’t somewhere to get people to write scripts for you.

martinbean left a reply on Notifications Without Eloquent User Model • 1 week ago

@ybert I don’t think it really matters if you’re using Eloquent or not.

Without digging into the code, when you apply the Notifiable trait to a class, it then attempts to call methods on the class such as routeNotificationsForMail(), so you will just need to implement those methods in your non-Eloquent classes.

You will need to change how you access the database notifications, though. You won’t be able to call $yourClass->notifications, for instance.

martinbean left a reply on How To Setup Custom If Statement • 1 week ago

@sktklaus You need to return a boolean from the closure. So if you want to check if the current user is an admin, do that check:

Blade::if('env', function ($environment) {
    return Auth::check() && in_array(Auth::user()->role == 'admin';
});

martinbean left a reply on How To Validate Double Values? • 1 week ago

@AbdallahSabri Just use numeric. A double is a numerical value.

If you need to do anything more specific, you can check the format using a regex validation rule.

9th July, 2018

martinbean left a reply on @$variable Usage • 1 week ago

@Sinden It’s nothing to do with Laravel; it’s a PHP feature.

Putting an @ symbol before a variable/function call is to suppress errors, so it’s a bit of a sloppy coding practice as it can make debugging difficult if that piece of code does trigger an error.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.