Robstar

at F9 Web Ltd.

Hire Me

Experience

74,930

15 Best Reply Awards

  • Member Since 4 Years Ago
  • 675 Lessons Completed
  • 3 Favorites

20th July, 2018

Robstar left a reply on Laravel 5.6 Scheduled Task Not Working As Expected • 1 day ago

As per the Laravel docs, the schedule:run task needs to run every minute.

I'd recommend you have a read of https://laravel.com/docs/5.6/scheduling

12th July, 2018

Robstar left a reply on Passing Laravel Object To Vue • 1 week ago

Have you defined the results prop within your scale component?

4th July, 2018

Robstar left a reply on The Beauty Of The URL • 2 weeks ago

There's nothing wrong with chanel.com example you've provided.

I try to keep urls as short as possible - shorter urls help seo. I'd argue that foo/username/work-name is inferior to /work-name.

With SEO urls you need to handle many things, some basics:

  • Changes to the slug - if you app allows this you need to 301 the old url to the new url
  • Changes to the url if using nested slugs i.e. if the clothing segment of /clothing/mens/shorts was changed, that would need to trigger redirects for all dependant urls
  • You'd also need to update sitemaps and internal links

I also hate url structures that don;t make sense. For example, given /foo/username/work-name, I should be able to browse to and /foo, /foo/username. Otherwise, I see no point in segmenting the url.

Robstar left a reply on Use Magento For CMS Or Build It Myself? • 2 weeks ago

Magento is an ecommerce platform with a fairly decent CMS.

If it's literally just a CMS you want, there are plenty of good ones around such as https://statamic.com/, https://pyrocms.com/ and https://octobercms.com/

3rd July, 2018

Robstar left a reply on Conflict Between Trait Constructor And Controller Constructor • 2 weeks ago

Surely you'd use a custom service provider here?

Robstar left a reply on Best Service Injection Syntax • 2 weeks ago

@megaman7 As you've only specified sending my email, the switch statement is probably overkill. If you reference Laravel Mail facade you easily swap out drivers within seconds i.e. Mailgun, Mailtrap, plain mail etc.. If you type hint the Mail facade, you won't be getting a huge benefit.

Do you wish to only ever send emails from your app or have functionality to swap out notification channels i.e. email, sms, slack etc.

Type hinting an interface as @Yorki did is more useful.

If you do wish to type hint the variable I believe you'd use https://laravel.com/api/5.6/Illuminate/Contracts/Mail/Mailer.html

2nd July, 2018

Robstar left a reply on Print True Or False Using Blade And Resources • 2 weeks ago

Slightly off topic, you can use early returns to clean up your controller i.e.

public function edit($id)
   {
       $banner = new bannersResource(bannersModel::find($id));

       if($banner){
           return view('admin.fragment.banners.form', compact('banner'));
       }else return back()->with('error','banner not found');
   }

becomes:

public function edit($id)
   {
       $banner = new bannersResource(bannersModel::find($id));

       if(! $banner){
        return back()->with('error','banner not found')
       }

       return view('admin.fragment.banners.form', compact('banner'));
   }

However, your example would be much better using route model binding that will automatically throw an exception. This means your controller method could be:

public function edit(Banner $banner)
   {
       $banner = new BannersResource($banner);

       return view('admin.fragment.banners.form', compact('banner'));
   }

Robstar left a reply on Private File Access • 2 weeks ago

I guess the obvious solution is to not use the public driver and store your files within a publicly accessible folder. Using random file names is also a bit of a naff solution.

Store the files in a private file system (i.e. AWS S3). When the user requests a file via a unqiue url i.e. /downloads/[file-hash-here] direct them to a controller;. Here you can verify all access to the file using middleware for example.

This method would generate urls like /downloads/w8q379trcb98wq3r. Alternatively, you could still use the file id within the url i.e. /downloads/123 if verifying ownership before downloading.

Robstar left a reply on Need To Print The Json Data Using Foreach Loop In My View Page • 2 weeks ago

Back on topic, I'd personally be preparing the JSON response into a neat array before passing it to my views.

This way you'll be looping through a standard array - no using "PHP" tags within your views to set temporary variables. This approach also makes your templates much more readable.

Robstar left a reply on Need To Print The Json Data Using Foreach Loop In My View Page • 2 weeks ago

Just FYI, Laravel 5.6 has nice Blade directive to render json, see https://laravel.com/docs/5.6/blade#displaying-data under the "Rendering JSON" section. So instead of

var app = <?php echo json_encode($array); ?>;

you could have

var app = @json($array);

Robstar left a reply on Setting Public Variables On Request Object • 2 weeks ago

Laravel has built in stuff for this - Gates (https://laravel.com/docs/5.6/authorization#gates) and Policies (https://laravel.com/docs/5.6/authorization#creating-policies).

However, for larger systems I always use https://github.com/spatie/laravel-permission as if offers most flexibility.

Saying that, if you're worried about running the same query in two files in your whole system, then I really wouldn't be.

You could use a Trait like https://github.com/michaeldyrynda/laravel-owns-models/blob/master/src/OwnsModels.php to make your comparisons more readable i.e.

$user = User::find($user_id);
$post = Post::find($post_id);

if ($user->owns($post)) {
    // Continue execution
}

if ($user->doesntOwn($post)) {
    // Generate some authorisation error
}

Robstar left a reply on Very Slow Search/sort Query • 2 weeks ago

If you're counting the likes each time, your app will become slower as time goes on.

Use "counter caching", something Jeffery does in The TDD forum series. In your articles table add a column called likes_count. When there is a new like increment this value. This is value you'd use within your filtering.

See: https://github.com/JeffreyWay/council/blob/master/database/migrations/2017_03_15_175959_create_threads_table.php#L21

https://github.com/JeffreyWay/council/blob/master/app/Reply.php#L40-L44

Personally, when there is a new "like" I'd dispatch a queued job to increment this value. However, you can do this directly within the model, as demonstrated in the links above.

29th June, 2018

Robstar left a reply on SMS Template In Blade • 3 weeks ago

@amirhazz I wouldn't classify sprintf as lazy at all. SMS is literally just text. At most, I'd use Laravel's lang helper with placeholders, i.e.

$message = __('Hi, :name, how is your :type subscription?', ['name' => $user->name, 'type' => $user->subscription->type]);

27th June, 2018

Robstar left a reply on Service Class Logic And Pattern Best Practices. • 3 weeks ago

If your service is just crud/database operations, it's more of a repository than a service.

In your controller you'd see descriptive methods like:

public function users(UserRep $repo)
{
   // $team is fetched elsewhere ...
   return $repo->findByTeamId($team);
}

However, you need to be careful as it's easy for your Repository to turn into an unnecessary wrapper for Eloquent - which your Service above pretty much is.

Robstar left a reply on Future Of PHP Laravel • 3 weeks ago

Yawn ...

Robstar left a reply on Programmatically Registering Users As If Going Through Registration Form • 3 weeks ago

Have a service that handles logic to register a user. Use that within both controllers.

Robstar left a reply on Going From Page To Other Without Any Refresh • 3 weeks ago

"jungle"?

Robstar left a reply on Playing With Laravel But No NPM And Node.js • 3 weeks ago

It appears you have a a managed server with a limited Cpanel account and no root access. I'm not sure why your host would say it;s not possible to install Node, as it's just a server at the end of day.

The first result in Google states otherwise too :)

https://www.simpleservers.co.uk/clients/whmcs/knowledgebase/605/Install-nodejs-on-Cpanel-Server.html

If you're just testing, I'd recommend setting up a local environment yourself using Homestead or Laradock. That gives you a server, for free, that you can experiment with.

If it's a real site I'd personally go for DigitalOcean or AWS.

For the record, you CAN use Node on your server - your host is being a pleb and unhelpful :) If you have a good managed host they will install things for you.

Robstar left a reply on Cleaning Up A Method • 3 weeks ago

This bit is unnecessary:

if(auth()->user()->type == 'admin')
        {
            $approved = '1';
        }
        else
        {
            $approved = '0';
        }

If you don;t have an accessor on your model you could quickly do:


$approved = auth()->user()->type == 'admin' ? 1 : 0;

I'd personally extract the image upload logic to a resusable service and dispatch that to a queue.

In relation to your last question you could do use observers. Alternatively you could simple merge data into the request:

request()->merge([
   'slug' => str_slug($request->input('title')), 
   'user_id' => auth()->id()
]);

$post = Post::create($request->all())
                    ->setCoverImage($request->file('cover_image'));

Robstar left a reply on Best Way To Learn Forge? • 3 weeks ago

I'm not really sure what there is learn per se. With a couple of clicks Forge helps you provision a server, install an SSL, setup queues etc. The majority of the fields within Forge are quite self explanatory imo.

There's a tutorial from March 2018 (the Laracasts series is unfortunately dated now) at https://code.tutsplus.com/tutorials/deploy-php-web-application-using-laravel-forge--cms-30329 that may help.

24th June, 2018

Robstar left a reply on Array_merge In Laravel Not Working • 3 weeks ago

Assume you've checked folder permissions, allowed memory amount on the server? Have you tried uploading a very small image first with one thumbnail size.

Robstar left a reply on Laravel HTTP ERROR 500 On Hos • 3 weeks ago

The PHP version on the command line and version used to serve the site will sometimes differ too. i.e. the output of phpinfo() may state 7.1, but when determining the version via php -v it states 7.0.

On some shared hosts they set the php path in none standard places and sometimes rename the php binary. i.e. on a crappy shared host I use for legacy sites they have binary for each supported version php56, php72 etc.

Try typing in php and then pressing tab for suggestions, or running which php to give a list og locations where your binary may be.

I know cpanel sites do something similar to this.

You could host on an AWS nano, which is basically free and will give you full control of the server.

Robstar left a reply on Basic Supply And Demand Algorithm In Php • 3 weeks ago

This is simply domain logic that you need to research and understand yourself. Maybe a client meeting is required too.

Robstar left a reply on How To Link Bootstrap To My Blade File In Laravel Npm Install? • 3 weeks ago

All is explained within the docs. It's well worth taking time to read them :)

In answer to your question, see https://github.com/laravel/laravel/blob/master/resources/assets/sass/app.scss#L9

Then in your blade file simply reference the css file, which will be at /css/app.css. YOu will need to run npm run devto compile assets.

Further information available at https://laravel.com/docs/5.6/mix

18th June, 2018

Robstar left a reply on Default Authentication CSS • 1 month ago

It depends on how you're importing the file. This could do directly within your SASS files or via updating your package.json file.

17th June, 2018

Robstar left a reply on Link At The Bottom To Facebook Doesn't Work • 1 month ago

The link works. Facebook displays the message "Sorry, this content isn't available right now", which is normally related to page visibility settings within Facebook..

Robstar left a reply on Dropping And Adding Columns To A Table • 1 month ago

@CG all is explained in the official Laravel docs, see https://laravel.com/docs/5.6/migrations#migration-structure

16th June, 2018

Robstar left a reply on Blade In Filname • 1 month ago

@AntonyRayan Configuring a database is very basic stuff, covered in depth in the docs at https://laravel.com/docs/5.6/database.

Environment variables are also basic stuff, all covered within the docs. See https://laravel.com/docs/5.6/configuration#environment-configuration

I'd really recommend you spend time readying the docs and getting used to the basics.

13th June, 2018

Robstar left a reply on Prevent Users From Accessing High-sensitive Data By Simply Changing Query String • 1 month ago

You'll need to use policies or even add a midldeware. As you appear to have already associated users with teachers.

12th June, 2018

Robstar left a reply on How To Store IMAGES Outside Public Folder • 1 month ago

@Dev0ps - all is explained in the documentation at https://laravel.com/docs/5.6/filesystem#the-public-disk

If using the public disk files will be physically stored in a none publicly accessible directory. Yiu need to symlink that directory so it's accessible. Laravel has a buiolt in command for that too (again described in the docs):

php artisan storage:link

9th June, 2018

Robstar left a reply on What Can You Tell From These Test Results? Api Pressure Test. • 1 month ago

@behnampmdg3 Is there any need to do select * for every query?

Robstar left a reply on Which Directories / Files Can I Remove Safely From The Laravel Package? • 1 month ago

@Cronix Or if using Forge I can just push to master :) For none Forge sites I use https://laravel.com/docs/5.6/envoy

Robstar left a reply on Which Directories / Files Can I Remove Safely From The Laravel Package? • 1 month ago

@jmar83 Firstly, the files you are deleting are key files. In relation to deployment, as long as you have SSH access you can still deploy your site properly (certainly better than uploading via FTP *** shudders***).

Deploying via FTP is just plain wrong. Git is the correct way if you have git on your server.

You should also try deployer.org or https://github.com/git-ftp/git-ftp

However, the best solution is a proper server or host that supports git (plenty of shared hosts increasingly do).

You could also create a patch file using git diff and pipe that to the zip program. You'd be left with a zip file containing the changed files only. You'd run a command something along the lines of (i.e. assuming you wanted the difference between the master and production branches):

git diff --name-only origin/production..origin/master | zip patch_$(date '+%d-%m-%Y-%H-%M-%S').zip [email protected]

8th June, 2018

Robstar left a reply on Which Directories / Files Can I Remove Safely From The Laravel Package? • 1 month ago

Wait, you just said you removed .gitignore, artisan, composer.json and composer.lock - wtf? Additionally those files are tiny in size. Hope I never have to work on one of your projects :/

7th June, 2018

Robstar left a reply on How To Correctly Write A Unit Test For Controllers Methords In Laravel 5.5? • 1 month ago

@valeraefimov696 Are you using the default Laravel Auth driver, or have you written your own custom driver?

Robstar left a reply on Which CSS Framework Is Best For Vue Js App (Enterprise Level) • 1 month ago

How has https://tailwindcss.com/ not been mentioned yet? :)

Robstar left a reply on Eloquent Custom Collections • 1 month ago

@naing Yes, try it for yourself :) Part of development is experimentation. All you've done here is extend the Laravel Collection class, which is basic PHP. You can add whatever methods you wish.

If overriding base Collection methods you will need to take care though.

3rd June, 2018

Robstar left a reply on Why Are Some Container Bindings Not Interfaces? • 1 month ago

@RoboRobok Whilst this is the container Laravel uses, or anything to do with Laravel, http://php-di.org/doc/understanding-di.html#the-theory provides some good information on using containers.

https://jtreminio.com/2012/10/an-introduction-to-pimple-and-service-containers/ is also worth a read. The example again use a different container ("Pimple") but I'm sure it will help.

1st June, 2018

Robstar left a reply on Cannot Read Property 'headers' Of Undefined When I Run Npm Run Generate • 1 month ago

The last time I saw a similar error was when trying to set default auth headers for Axios, which was trying to take an API key from a meta tag within my template.

When I set the correct meta tag everything worked fine.

Robstar left a reply on Displaying A Dropdown Depending On Whether Or Not There Are Values In The Database • 1 month ago

Could make it slightly more readable imo:

@if($product->flavors->isNotEmpty())
   <select id="product-flavor" class="bs-select">
    @foreach ($product->flavors as $flavor)
       <option value="{{ $flavor->id }}">{{ $flavor->name }}</option>
    @endforeach
  </select>
@endif

Robstar left a reply on Why Are Some Container Bindings Not Interfaces? • 1 month ago

I get most use out the container when a class has lots of dependencies to instantiate it:

$service = new SillyService(Adaptor $adaptor, Client $client, Resolver $resolver, Template $template);

Using that in multiple locations would be an issue.

Using the container I can use it via:

$service = resolve(SillyService::class);

as the container will resolve all dependencies for me. I tend to put things like this within it's own service provider for convenience.

Robstar left a reply on Database Structure For Managing Content With Different Page Templates • 1 month ago

It depends, it's not necessarily going to take a lot of time, it depends upon how complex things need to be. It could be as simple as the below.

Create a templates table - that just contains the name and maybe an optional description field (for use in admin areas). Each name corresponds to a blade template file.

Each page would be assigned a template.

Within your controller load the blade template based upon the page template.

Example, a full width template for privacy policies. Or maybe a news listing template that displays the content in one column and the latest news posts in another column.

If each page has its own relationships (i.e. forms, field etc. as you mention above), you can display these as required within each template. You'd use Blade partials and components to avoid duplication.

The above assumes you have a set list of layouts that not editable by the client. For the majority of the time that's fine.

Robstar left a reply on Get Json Data From Laravel To Android • 1 month ago

@lara_mk Please read the documentation, everything is there for you. In this case, returning an Eloquent collection will automatically return JSON, as the response above you stated too.

29th May, 2018

Robstar left a reply on How To Implement Facebook Pixel In Laravel? • 1 month ago

Since when has Facebook Pixel been anything to do with Laravel?

Robstar left a reply on Dynamic Mailable From() • 1 month ago

If the to email is stored in the database why not query your model before sending the email? It seems an odd choice to place sensitive information within hidden form fields.

12th May, 2018

Robstar left a reply on Get User Location With Laravel And Vue • 2 months ago

What have you tried so far?

Robstar left a reply on Problem With ToFixed • 2 months ago

this.data.ticket_price look suspect, the error is saying that value is not defined.

Whilst this.data.ticket_price is necessarily incorrect, are you sure it shouldn't be this.ticket_price.

Either way, what is the result of you logging this.data to the console?

Edit Your Profile
Update

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