Screenbeetle

Screenbeetle

Member Since 3 Years Ago

Heart is still in Bristol

Freelance Web Developer at home in Norwell

Experience Points 52,520
Experience Level 11

2,480 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 301
Lessons
Completed
Best Reply Awards 33
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

19 Mar
1 day ago

Screenbeetle left a reply on How To Make A Printout In Laravel

Hi @abdulbazith

Using barryvdh/laravel-dompdf have you tried $pdf->stream(); instead of $pdf->download();?

This would open the purchase order as a pdf in the browser without having to download. You can then just click print (and then also save it as a download if you wanted).

My customers either do this or just use a print friendly html page like @Sergiu17 suggested

18 Mar
2 days ago

Screenbeetle left a reply on Disable Url If Page Is Not Published

You may be overthinking this.

One simple option is to have a condition in your PageController's show method (or CmsController's frontPage method as you have it) to check the draft status and have different return statements depending

Firstly its worth noting you can use a url slug as a unique identifier in your page (or cmspage) model. You just need a unique slug field in your pages table and then add this to your model:

public function getRouteKeyName()
{
    return 'slug';
}

at this point Laravel route model binding will get the model from the slug instead of id.

 // you have this as frontPage($url) but it seems like a show method
public function show(Page $page)
{ 
    if($page->status == 'draft){
        return redirect('somewhere');
    }

    return view('frontend.frontpage', compact('page')); 
} 

Screenbeetle left a reply on Should I Define Mysql Relations When Using Alequent

Hi @nikos

isn't that adding foreign keys to SQL actually, just via migrations yes that's right

Screenbeetle left a reply on Should I Define Mysql Relations When Using Alequent

Morning @kisaw88

.. @nikos is correct but just to add you can still add foreign key relations in Laravel. You do this in the migrations. You can see examples in the docs here: https://laravel.com/docs/5.8/migrations#foreign-key-constraints

Screenbeetle left a reply on Laravel Snappy PDF - Loading External/Internal CSS - Tailwindcss If Possible

I've had a nightmare with this also last year. You might find something helpful in here: https://github.com/barryvdh/laravel-snappy/issues/258

After wasting half a day on it last time I am ashamed to say I just went back to building my pdf using tables and inline css. I'm planning another go soon so I'll report back if I get anywhere. Be keen to see what solutions you come up with to

16 Mar
4 days ago

Screenbeetle left a reply on Auth::attempt Method Always Bind With Users Table?

Evening.

By default Laravel Auth uses the users table. Do you want to rename the users table? Here is a good tutorial based on Laravel 5.3 (so may be a little out of date): https://www.youtube.com/watch?v=Aso3e_lQju4

Or do you want Auth::attempt to check more than one table? That's not possible. It just lets you check extra fields on 1 users table e.g. Auth::attempt(['username' => $username, 'password' => $password, 'email_confirmed' => 1]))

Screenbeetle left a reply on Tracking Visitors Of Specific Url

I've not used it before but one option is the Google Analytics API. This Laravel Package is a wrapper for it: https://github.com/spatie/laravel-analytics

I guess you'll need data for specific urls relating to your business customers. I image this is possible but you'll need to have a play. This tool may help explore api queries: https://ga-dev-tools.appspot.com/query-explorer/

Screenbeetle left a reply on Laravel Accessor Appends Not Working As Expected / Strange Behavior

Sorry @jaheller - I'm am at a kids party so it's hard to answer ..

I don't think you need an accesser here - just a method to get the currentLevel. Can you not just define the three relations and then do the logic to return either vendor or user level in one method? Something like:

public function vendorUser()
{
    return $this->hasOne('App\VendorUser');
}

public function vendorLevel()
{
    return $this->hasOne('App\VendorLevel');
}

public function userLevel()
{
    return $this->hasOne('App\UserLevel');
}

public function currentLevel(){

    // if condition here for what comes back on $this->vendorUser
    // then return either $this->vendorLevel or $this->userLevel
 }

Screenbeetle left a reply on Laravel Accessor Appends Not Working As Expected / Strange Behavior

Passing a value like that is just the laralavel suggested way of doing it: https://laravel.com/docs/5.8/eloquent-mutators#defining-an-accessor

Things do look overly complicated in your model there. Your accessor is returning the hasOne relation at the moment where it should be returning a simple field value. Is the field you want to get on VendorUser? If so then your accessor should be on that VendorUser model not user.

15 Mar
5 days ago

Screenbeetle left a reply on Where To Put Workflow Code

Hi @christiant

I think you'll struggle to get many replies with questions as broad as this - it's a lot to take in!

You'll be better off breaking questions into smaller bite-sized pieces and showing some code. A lot of the weirdos on this forum can make more sense of code than big blocks of text - myself included :-)

Screenbeetle left a reply on Error Messages In Request Validation

It looks like you have two error loops. There is one in the code above. Is there another loop above this code - maybe in the parent view if this is a partial?

Screenbeetle left a reply on Laravel-snappy And Many Different Views

Sorry @cemcminn - the question is a bit unclear

When you say

The tutorial shows building the data from one source by finding it again in the above method call and it works for the first document I tried, but I won't always need just that one table.

Can you rephrase that - maybe with example code? Do you mean how to pass different table data to the loadView method?

Screenbeetle left a reply on Throw New MethodNotAllowedHttpException($others)

Maybe unrelated but I don't think the form facade needs the separate {{method_field('PATCH')}} statement. You can just add patch instead of Post here:'method' => 'PATCH',

Laravel Collective no longer support the Form facade and pulled the docs .. which makes it a little tricky to cross reference your code.

I do vaguely recall having similar oddball issues with the Forms facade in the past though. My fall back approach is to just rewrite the form not using the facade. Even if this doesn't fix the issue it often helps to rethink and reveal what's going wrong.

Screenbeetle left a reply on Tracking Visitors Of Specific Url

Sorry - why not just use Google Analytics? Or are you asking how to set it up?

Can you add more detail about what you need exactly

Screenbeetle left a reply on Laravel 5.7 Files Merge

Why don't you just zip and download the files using a package like Laravel Zip?

https://github.com/zanysoft/laravel-zip

14 Mar
6 days ago

Screenbeetle left a reply on How Do You Manage A View That Is Getting Big Like This Going Out Of Control?

Yes indeed - use more partials with @includes.

I would start by extracting out your forms. Then also your breadcrumbs and alerts. Remember you can use @yield in partials too - for example to add the current page in your breadcrumb trail.

Screenbeetle left a reply on Career As A Software Developer

If you get the model right you can always become a freelancer later on - or even a small business of your own with a friend or two. Don't expect bliss but you can build up a decent income and be in more control of how and who you work for.

If you want to give the sector a good go I'd personally suggest: -getting the industry expected 2 years working in a job/s first -and then contract for a bit with an Agency.

Contracting is good money but more importantly you get a diverse amount of exposure with different practices. It can still occasionally be mindbogglingly frustrating with indifferent co-workers but it's invaluable experience to help guide you in the direction you want to go in. It may well put you off forever but at least you'll properly know you gave it a good go

I intend to be in the worm cozy womb of retirement in 15years time - but I'm 44 now so probably not a good role model.

12 Mar
1 week ago

Screenbeetle left a reply on Adding Multiple Github Accounts To Forge

Hi @nickdavies07 - did you get a resolution to this by any chance?

Screenbeetle left a reply on Apply Middleware When URL Pattern Matches

Hi @akogler

As you are assuming a logged in user - Auth::user()->id - you ought to Authenticate the UserProjectFit routes as well. At the moment it looks like non logged in users can hit those routes which will throw a property 'id' of error non object error.

If you auth the routes first it will nicely redirect non logged in users without error. You can add multiple middleware by comma separating: ->middleware('Auth', 'UserProjectFit')

11 Mar
1 week ago

Screenbeetle left a reply on Nova Saves File As .bin File

Hello again @emotality - we fixed our project.

For us it was a file upload issue outside of Nova but I think the two issues are the same.

When uploading a file the ->store() method uses Illuminate\Http\UploadedFile. By default this hashes the name and then tries to add back the extension by working out the mime type from the contents of the file itself - which doesn't always work. The docs explain it like this:

The UploadedFile class also contains methods for accessing the file's fully-qualified path and its extension. The extension method will attempt to guess the file's extension based on its contents. This extension may be different from the extension that was supplied by the client

https://laravel.com/docs/5.8/requests#files

The fix for us was to use the storeAs method instead and use the original extensions as part of the name:

->storeAs(
                'files',
                sha1(time()) . '.' . $file->getClientOriginalExtension()
            );

As Nova also uses Illuminate\Http\UploadedFile you should be able to add an override in your model to use storeAs in the same way - something like:

public function fields(Request $request)
{
        return [
          
            File::make('File')
                ->storeAs(function (Request $request) {
                    // something similar to the above
                })
        ];
}

I should credit @edoc for this as he mainly figured it out!

08 Mar
1 week ago

Screenbeetle left a reply on Change Email Template

You'll need to explain more. For example?

Screenbeetle left a reply on Nova Saves File As .bin File

I've got a customer reporting the same issue but only occasionally - 3 cases out of a couple of hundred uploads and all in the last month. In case it helps someone spot a pattern my customer has so far reported 3 issues as follows:

1 Mac Pages document saving as .bin 1 MS Word for Mac saving as .bin 1 PDF saving as a .zip (not quite sure if the user uploaded this by mistake but they swear they didn't :-)

I'll report back if I work out what's happening

07 Mar
1 week ago

Screenbeetle left a reply on Adding Multiple Github Accounts To Forge

@nickdavies07 - I'm going to help bump this as I've been having the same issue this week on Forge / Digital Ocean. I've tried all that suggestions that come up in searches - as you seem to have - but nothing gives .. I get the same error as you.

My work around at the moment is just to ssh into the server and do a https based git clone to set up the repo and then git pull to deploy. That works but it's a hassle

Screenbeetle left a reply on Cloning Repo On Forge Error - Sed: -e Expression #1, Char 42: Unknown Option To `s'

Possible long shot but I wonder if it's related to this: https://laracasts.com/discuss/channels/laravel/beware-in-env-files

It seems to be failing at the point where it encounters a #

Screenbeetle left a reply on Move A File From Public/upload Folder To S3 Server

If you want to automate your backups then you can use [https://github.com/spatie/laravel-backup].

This will zip and store your database and/or directories to S3. Once set up you you can set several backup routines through theapp/Console/Kernal.php -> schedule method. For example once an hour for your database and once a day for your files

06 Mar
2 weeks ago

Screenbeetle left a reply on What's The Difference Between @yield And @include

Morning

@yield specifies an area in your layout like @yield('content') which your view uses to insert content @section('content') ... @endsection

@include is used to include partials within your views (e.g. @include('layouts.partials.header')

Screenbeetle left a reply on Getting A Collection From A Relationship

if you have the one to one relation set up in your cost item model:

public function poItem()
{
        return $this->hasOne(PoItem::class);
}

then you can loop through cost_items and get the po_item like this:

foreeach($cost_items as $cost_item){
$po_item = $cost_item->poItem->id; // or other field
}

Screenbeetle left a reply on How To Edit Laravel Field Validation Message ?

going down the rabbit hole now :-)

My final comment is to remove the old validation:

public function reponse(CustomRequest $request)
    {
    /* REMOVE THIS - you don't need it now
        $validation = Validator::make($request->all(), [
            'reponse' => 'required',
        ]);
        
        $error_array = array();
        $success_output = '';
        if ($validation->fails())
        {
            foreach ($validation->messages()->getMessages() as $field_name => $messages)
            {
                $error_array[] = $messages; 
            }
        }*/
...

I can't help with debugging the JS error output. I only like to suffer my own JS issues

Screenbeetle left a reply on How To Edit Laravel Field Validation Message ?

this is a classic Laravel / PHP issues. Check:

  • Does it existing in the Http\Requests\CustomRequest?
  • Have you name spaced it correctly?
  • Have you included it in the controller use App\Http\Requests\CustomRequest

etc

Screenbeetle left a reply on How To Edit Laravel Field Validation Message ?

Sorry @PhoeniX5 - this is a little rushed but something like this:

// This approach validates outside the controller so take out all validation from your controller
// and just replace with a CustomRequest

public function reponse(CustomRequest $request)
{
    // method stuff
}

then run php artisan make:request CustomRequest:

class CustomRequest extends FormRequest
{
    
    public function authorize()
    {
        return true; 
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'reponse' => 'required',
        ];
    }

    public function messages()
    {
        return [
            'reponse.required' => 'The reponse field is required etc',
        ];
    }
}

Any errors are put into the$errors variable. You can then check and display in your view:

@if ($errors->any())
    @foreach ($errors->all() as $error)
        {{ $error }}<br>
    @endforeach
@endif
05 Mar
2 weeks ago

Screenbeetle left a reply on Adding Current Item ID To Second Step In Form

No I don't think so (but depends on what you are doing). I try to keep things as CRUD like as possible for each resource - with separate controllers etc. It doesn't always work :-)

Screenbeetle left a reply on Adding Current Item ID To Second Step In Form

One option is to create the main table record in step one, then within the store method redirect to the next route with the record you've just created? You end up with something like this:

//step 1: create then store routes for main table record - then redirect to - 
Route::get('/orders/create', '[email protected]')
     ->name('admin.orders.create');

Route::post('/orders', '[email protected]')
     ->name('admin.orders.store');

// within the store method you can:
        return redirect(route('admin.orders.order-details.create', compact('order')));


// step 2: create / store routes for the second table
Route::get('/orders/{order}/order-details/create', '[email protected]')
     ->name('admin.orders.order-details.create');

Route::post('/orders/{order}/order-details', '[email protected]')
     ->name('admin.orders.order-details.store');

Screenbeetle left a reply on Question Regarding Best Practices For Filtered Routes

I would go with your latter option of query strings on the index route. Filters can stack up over time so this option is more flexible.

Screenbeetle left a reply on Move A File From Public/upload Folder To S3 Server

It may be easiest to do this manually.

Download all your files and then batch upload them through your S3 console. If you have many 1000s then you can use a client Forklift

Screenbeetle left a reply on Some Advice For Saving An Invoice

Others may have a better way but I would personally store an invoice number as an integer and then add the prefix in an attribute getter. If you're only ever incrementing a number you shouldn't run into the duplicate problem.

So you first change the invoice_number to be a unique int field. Then, as above, every new invoice is Order::max('invoice_number') +1;. To output the full invoice number format you do something like this:

public function getInvoiceNumberAttribute()
    {
        return 'ARM'. str_pad($this->invoice_number, 4, '0', STR_PAD_LEFT);
    }

just a thought

04 Mar
2 weeks ago

Screenbeetle left a reply on Configure Homestead On Nginx

To expand - Homestead also includes Nginx. Homestead is a bundle containing everything you need for development. What instructions are you following example and where have you got to?

Screenbeetle left a reply on Configure Homestead On Nginx

Morning. Sequel Pro isn't a database - it's just software to connect and manager your database. Homestead comes bundled with MySQL so you can create your database with that.

Screenbeetle left a reply on Some Advice For Saving An Invoice

Do you save the new invoice number at the same time?

Whatever you decide you first need to make the invoice number field unique.

Screenbeetle left a reply on Some Advice For Saving An Invoice

Unless you have a high traffic site it's unlikely but you can prevent it by setting the invoice_number field to unique - '->unique()' in your migration.

You can then increment the number for each new invoice. You just need to get the current highest number - Order::max('invoice_number');- and +1:

01 Mar
2 weeks ago

Screenbeetle left a reply on Conditional Validation Rule With Custom Message?

If you mean returning a flash message to the user then in you controller you:

session()->flash('message', 'Sorry one or task on this ticket an not complete');

Then in your view you need to catch and display the message:

@if($flash = session('message'))
        {{ $flash }} <!-- echo flash message -->
@endif

Screenbeetle left a reply on Searching Multiple Fields Over Multiple Tables

I just tested your second query with a local project and it does seems to work. My project has a one to many relationship between customers and orders. I changed your query like this:

$name = 'peter';
$prescription = 90;

return Order::whereHas('customer', function($query) use($name){
            $query->Where('name', 'like', "%$name%");
        })->orWhere('id', 'like', "%$prescription%")
          ->orderBy('id', 'DESC')
          ->with('customer')
          ->paginate(20);

and it returned a user with named peter and order with an id of 90.

Are you getting an error message? Or is it just not returning and results?

Screenbeetle left a reply on Laravel Htaccess Doesn't Work On Live Server

Also check your server isn't Nginx (e.g. like Digital ocean) - htaccess doesn't work with Nginx.

28 Feb
2 weeks ago

Screenbeetle left a reply on Searching Multiple Fields Over Multiple Tables

It's a bit hard to read your code (should add back ticks to format it) but it looks like your searching both tables within your closure.

Try separating out the search a little like this maybe (untested):

$results = HealthCheckup::where('prescription', 'like', '%' . $search_string . '%') // searches health_checks table
                    ->orWhereHas('user', function ($q) use ($search_string) { // searches users table
                        return $q->where('name', 'like', '%' . $search_string . '%');
                    })->orderBy('id', 'DESC')
                   ->with('user')
                   ->paginate(20);

Screenbeetle left a reply on How To Setup My Laravel Project In Digitalocean?

How comfortable are you with Linux command line admin? A raw Digital Ocean server needs a bit of work to first set up a user, assign privileges, set up a ssh key (to let you ssh in). At that stage you can then use Deployer to make things easier.

If this is all new (and even if it isn't) you should consider user Laravel Forge which essentially does everything for you - including setting up databases, deployment, ssl certs etc

Screenbeetle left a reply on How To Edit Laravel Field Validation Message ?

So you should know you can add validation in the controller right (see link above)? But to make things neater you can also use a separate validation request class using artisan: php artisan make:request StoreSomethingRequest

This creates a class in app/Http/Requests

This file has two elements. Firstly the rules and second the custom messages. It looks like this:

class StoreSomethingRequest extends FormRequest
{
    
    public function authorize()
    {
        return true; // this is set to false by default I think but needs to be true
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
        ];
    }

    public function messages()
    {
        return [
            'name.required' => 'Please add a name',
        ];
    }
}

Then in your controller you swap the defaul Request $request object for you custom validation request object

    public function store(StoreSomethingRequest $request)

Screenbeetle left a reply on How To Edit Laravel Field Validation Message ?

you can do this in a custom request class by adding a messages method - e.g:

 public function messages()
    {
        return [
            'field_name.required' => 'my custom message here',
        ] ;
    }

Screenbeetle left a reply on SQLSTATE[23000]: Integrity Constraint Violation: 1062 Duplicate Entry

You have the name field set to unique which means you can't have two names the same. Some options to consider:

  1. Change the name field to not be unique
  2. validate the posted data and tell the user that the name already exists and try again
  3. add a unique suffix / prefix to the name to guarantee it is unique (seems a bit odd)
27 Feb
3 weeks ago

Screenbeetle left a reply on First Time Model Binding

Vilfago's answered your question but just to chip it's not what's referred to as [route] model binding

route model binding is a Laravel trick to fast track getting the model - for example:

Route::get('/type/{type}', '[email protected]');

// then in your controller show method you:
public function show(Type $type)
{
        return view('type.show', compact('type'));
 }

12 Feb
1 month ago

Screenbeetle left a reply on Laravel Project Inside Another One

ok - if this is new then I would definitely avoid trying to put project2 inside project1. That will get messy.

What exactly is new - setting up a subdomain? If so then it's done via your dns settings. Just set up project2 as a separate project then point an A record at it like this DNS entry Type Destination/Target: project2 A ip address of server

Screenbeetle left a reply on Laravel Project Inside Another One

This sounds like a massive headache :-) For a start, Laravel needs composer dependencies to work which live outside public.

Are you trying to access your second project from a subdirectory (e.g. www.domain.com/project2)? If so why don't you move project2 to a suddomain (project2.domain.com) and treat it as a separate project with it's own repo etc? You can still share a database if that's what you're trying to do.