Resin

Resin

Member Since 3 Years Ago

Odder

Programmer at Aalund

Experience Points 11,720
Experience Level 3

3,280 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 100
Lessons
Completed
Best Reply Awards 10
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.

15 Mar
2 months ago

Resin left a reply on Call To Undefined Method Illuminate\Support\Facades\Gate::before()

@towhid When using the Contract you should inject it in the method. When using the facade you should use Gate::

14 Mar
2 months ago

Resin left a reply on Call To Undefined Method Illuminate\Support\Facades\Gate::before()

Try importing the contract instead.

use Illuminate\Contracts\Auth\Access\Gate;

Resin left a reply on How Does Laravel/Blade Handle Assets ?

Try reading up on the asset helper function. You can set the assets folder to be global_assets in your .env file and then use the helper function.

https://laravel.com/docs/5.7/helpers#method-asset

Resin left a reply on Gzip Compression Not Working/showing

Are you running apache or nginx?

Resin started a new conversation Laravel In Docker Using Storage Symlink

I am having some issues with the storage symlink when using docker.

php artisan storage:link

I can make the symlink either from inside docker or from the host computer.

Inside docker: Works with urls in the browser. Fails when trying to embed the file inside an email

On host: Works in email embeds Fails in browser urls

Does anyone know of a way to get this working properly?

13 Mar
2 months ago

Resin left a reply on How To Return Value Without The Column Name?

return response()->json(['rid' => $role_name->role_name], 200);

Resin left a reply on To Define Constant With Define() Function In Config/constant.php. Can We Say It Is Laravel Way??

I believe that the laravel way is to set it up in an array as in the other config files, and use config('contant.my_constant') to get it :)

Resin left a reply on Displaying One To Many In Blade

You have defined a hasMany relationship. This means that$ booking->getBookingDetails return a collection of detail instances, not just one.

Either look over all of your $booking->getBookingDetails (using another foreach) or change your relationship to a hasOne.

12 Mar
2 months ago
08 Mar
2 months ago

Resin left a reply on Display Custom Error Msg

Nope, but you can catch the error

try {
   $model->findOrFail($data);
catch(ModelNotFoundException $e) {
     return response()->json(['status'=>'succ' 'msg'='error msg'], 404)
}

Resin left a reply on Failed To Load Resource: The Server Responded With A Status Of 403 (Forbidden) In My Public Folder

You are loading the files directly from their site which they do not allow. Instead download the files and pub them in your local public folder and reference them in there instead. https://fullcalendar.io/docs/installation

 <link href="{{ asset('lib/jquery.min.js') }}" rel="stylesheet">
 <link href="{{ asset('fullcalendar/fullcalendar.js') }}" rel="stylesheet">

Etc. Change the above to the actual structure you are using.

Resin left a reply on Failed To Load Resource: The Server Responded With A Status Of 403 (Forbidden) In My Public Folder

Are you actually loading the content from your own server? This is a proper url https://fullcalendar.io/js/fullcalendar-3.1.0/lib/jquery.min.js Can you show how you included the js in your view?

Resin left a reply on Cannot Use A Scalar Value As An Array

Yeah sure. == means loose comparison (eg. "0" == 0 is true), while === means strict comparison (eg. "0" === 0 is false while 0 === 0 is true)

But as @skycoder mentioned you dont need to explicitly check. If the array is empty then count will return 0 which is the same as false.

Read this for more information http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting

Resin left a reply on Getting Alternate Rows To Be Different Colors In A Pdf

Did you read the provided link?

Snippet:

PDF documents internally support the following fonts: Helvetica, Times-Roman, Courier, Zapf-Dingbats, & Symbol. These fonts only support Windows ANSI encoding. In order for a PDF to display characters that are not available in Windows ANSI, you must supply an external font. Dompdf will embed any referenced font in the PDF so long as it has been pre-loaded or is accessible to dompdf and reference in CSS @font-face rules. See the font overview for more information on how to use fonts.

More info here: https://github.com/dompdf/dompdf/wiki/About-Fonts-and-Character-Encoding

Resin left a reply on Getting Alternate Rows To Be Different Colors In A Pdf

It is based on this package, so I would suggest reading their documentation. https://github.com/dompdf/dompdf

Regarding the alternating row color, I would suspect that it does not work with :nth-child. Instead try adding a class name to every odd row and give that class a different color

.invoice_table .table .tbody .tr.odd {
                background-color: #4C8BF5;
                color: #fff;
            }

Resin left a reply on Cannot Use A Scalar Value As An Array

I know :) Just thought it would be good for the person to learn things little by little. In their case it would then be.

 if (!count($po_items)) {
            return redirect()->route('employee.poitem.pending');
        }

Resin left a reply on Sorting String As Number

Actually it seems that laravel collections also supports this.

$collection->sortBy('unit', SORT_NATURAL);

Resin left a reply on Sorting String As Number

You could probably sort them after getting them from the database using something like natsort http://php.net/manual/en/function.natsort.php

Resin left a reply on Cannot Use A Scalar Value As An Array

Do this instead

$po_items = [];
        foreach($cost_items as $cost_item){
            if ($cost_item->status == 0) {
                $po_items[] = $cost_item->po_item;                
             }
        }
        
        if (count($po_items) === 0) {
            return redirect()->route('employee.poitem.pending');
        }

Resin left a reply on Load Data From Bd Globally

You could perhaps make a helper function (make a helpers.php file and add it to composer.json)

"autoload": {
        "files": [
            "app/helpers.php"
        ],
}

In there you can call your options

function getOptions()
{
    return Facades\App\Options::getOptions();
}

Now you can just call getOptions() whereever you like

Resin left a reply on Recommended Redis Version

Good catch. You are of course right it is 3.2.6, not 3.6. But the question remains :)

07 Mar
2 months ago

Resin left a reply on Load Data From Bd Globally

Add a method for getting them instead on the Options model. This caches it to an array in memory for the duration of the call.

public function getOptions()
    {
        return Cache::store('array')->remember('options', 1, function () {
            return Options::all();
        });
    }

Now anywhere you need the options, just call

$options->getOptions();

Resin left a reply on Hello How To Apply This Query In Laravel

The problem is that is says price_before AND price_after should both not be 0. So when one is 0 it fails The new one makes the following query

select * from `products` where `price_before` != 0 or `price_after` != 0

Notice that is says OR instead of AND. This implies that just one of them must be true to return a row

Resin left a reply on Api Call Results Limit

That is most likely a restriction set by the owner of the API. Can you add an offset? If so you can query multiple times and get 100 at a time.

Resin left a reply on Hello How To Apply This Query In Laravel

Try this instead

$products = Product::where('price_before','!=',0)
                            ->orWhere('price_after','!=',0)
                        ->get();
return ProductResource::collection($products);

Resin left a reply on Hello How To Apply This Query In Laravel

Can you open you database directly (in heidisql or dbeaver etc) and copy/paste that query in?

select * from `products` where `price_before` != 0 and `price_after` != 0

Does it return any rows?

Resin left a reply on Finding The Object Key With The Value Inside The Array?

const attribute = 'livingType';

for (let key in mapData) {
    if (p.hasOwnProperty(key) && p[key].indexOf(attribute) >= 0) {
        return key;
    }
}

Resin left a reply on Hello How To Apply This Query In Laravel

That should work. Can you try

dd(Product::where('price_before','!=',0)
                            ->where('price_after','!=',0)
                        ->toSql());

Resin left a reply on Failed To Load Resource: The Server Responded With A Status Of 403 (Forbidden) In My Public Folder

What happens if you open one of the urls in a new tab directly? eg. YOURURL/fullcalendar.io/js/fullcalendar-3.1.0/lib/jquery.min.js What type of operating system are you running? Windows or linux?

Resin left a reply on Hello How To Apply This Query In Laravel

Can you show an example of a line from your database you would expect to get with this query?

Something like?

price_before | price_after
0                     | 0                         <-should not be found
22                   | 0                         <- should be found

Resin left a reply on Rule Engine - Bind To Specific Model

I have implemented something very similar for a project I am working on. The way I handled it was to save the conditions as a tree Eg. in your case there would be 1 root element with A and B (a column for each pointing to a new id) A points to the first rule and B point to the second. Now I start with setting the default return to false, and the check A and B. The result of each i run though

if(A && B) {
    return true
}

Now this is taking further by expanding the tree A can point to first rule, and B can point to a new branch which then points to a new A and B (thereby having 3 rules).

This might seem complex but after building a recursive function it works quite perfect :)

Resin started a new conversation Recommended Redis Version

I am just setting up a laravel website on a debian machine, and I am working on getting redis up and running. For some reason debian 9 only have redis 3.6, so I was wondering which version of redis is recommended. Is there any reason to build redis 4 or 5 for debian or is 3.6 fine?

17 Jan
4 months ago

Resin left a reply on WhereHas Using Muliple Tables (or Perhaps Join)

It is a great idea. Sadly it is a database used by another system (not created in-house), and I cannot edit it in any way. I got it working using some some join and raw.

Resin left a reply on WhereHas Using Muliple Tables (or Perhaps Join)

That was what I was afraid of :(

Resin started a new conversation WhereHas Using Muliple Tables (or Perhaps Join)

Hi I have 3 tables. users, pages and user_groups Each user is part of a user group and on the table is a max_pages column. Now I need to get all users that still have not exceeded their max_pages count.

Is there an eloquent way of doing this or do I need to use the query builder. I was hoping that I somehow could use whereHas but I cannot get it to work at all, sadly.

I am using mssql and laravel 5.7

20 Dec
5 months ago

Resin started a new conversation Mail In Laravel

I am working on a a system where you can setup an email on our website, with realtime preview using JS.

My issue is that I expect to save the mail as markdown which can be used for both preview and mail. Now the issue is that I also need it to inline all css to ensure it works properly on websites. The markdown version supports inline css but not embedded image The view/html version supports embedded image (expect for in preview) but not inline css.

Has anyone tried something along these lines before that have a good idea of how to do it properly?

Thanks

Resin left a reply on Mail Markdown

So you want the subject to both be the subject and be inside the mail body? If not then all you need is this. No need to pass the $sub to markdown()

->subject($sub)

I believe that what you are seeing is just googles default preview. They will always render the title, and then x number of characters from the email body. My best bet to avoid this is to override the text version of the mail with a version without $sub, and hope that gmail will use this in their preview.

Resin left a reply on Mail Markdown

In your mail.message you have it defined? Remove # {{$sub}} and you should be fine

Resin started a new conversation Embed Images In Markdown Mails

I can find a few posts around the web stating that embedding emails was broken in 5.4. We are not in 5.7 but I can't seem to find a way of getting it to work. I prefer to use the CID: embed method used in normal emails.

Anyone know how to get this working? I would hate to be forced to scrap my markdown implementation and start over

08 Nov
6 months ago

Resin left a reply on Migrating With Connection

Thanks. Figured it out as well. Seems that it does it correctly as long as the database it goes in artisan migrations has full access

Resin started a new conversation Migrating With Connection

I have a stange setup where I load data from an external database, which means I cannot add tables there. This means I have created a new database on which I wish to run users migrations and such. I have also created a migration of each table in the external database, to use when testing. Now for each migration I have set a connection using Schema::connection('other_db') (or ('testing_db')). The problem comes when I try to migrate. As my default connection is the external database, laravel seems to think it should use that for something. This means I get an error (Cannot find the object "DBVersion" because it does not exist or you do not have permissions.)

It works if is set the DB_CONNECTION to my own DB, but this means I need to change the connection manually in most of my application :(

Is there any way to get laravel to actually respect the connection set on the migrations from the start?

31 Oct
6 months ago

Resin started a new conversation Using Testing Connection On Model With $connection Set

Hi I am using an external mssql database for getting misc data. In the models for these I have set the connection to use. I have also built in some tests for each of these to ensure that my code works with the provided data.

Now my issue comes as I have setup a testing connection using sqlite->:memory. It is correctly setup in my phpunit.xml file but for some reason laravel seems to think that it should use the connection set inside the model instead.

Is this a bug or am I missing something? Is it just not possible to test a model with a specified connection?

Thanks!

22 Aug
8 months ago

Resin left a reply on Session ..difference Axios/Laravel

I have this exact issue. How did you solve it?

14 Aug
9 months ago

Resin left a reply on Avoiding Making Same Query Over And Over

Ended up doing this (and it works)

public function getDefinitions($project_id)
    {
        return Cache::store('array')->remember('definitions', 1, function() use ($project_id) {
            return Definition::where('project_id', $project_id)->get();
        });

    }

Resin started a new conversation Avoiding Making Same Query Over And Over

I am trying to set up a resource collection (a sub child of my parent resource collection).

For each item there is a chance that it needs some extra data for adding to ajax. Now there are quite a few items and currently I am having to get the same "extra data" for each and every item that needs it. Does anyone have any bright ideas of how to avoid doing this? My only idea is to load it all the way up in the first resource and pass it down all the way, but I hope there is a more clean way of doing it.

The structure is like this.

QuestionCollection->Question->SpecialActionsCollection

Thanks!

31 Jul
9 months ago

Resin left a reply on Factory Make With Relationship

Yeah but sadly that requires me to add more than on question (if you set the 3 after class to one, it just returns a boolean).

Resin left a reply on Factory Make With Relationship

As far as I understand you can only use this to persist the relationship in the database and get back the id to use as reference. It does not actually return the relation. I would need to use load() or the likes afterwards to load the relationship (which in turn would require me to persist the data using create() instead of make()

Resin started a new conversation Factory Make With Relationship

Hi

Does anyone know if it is possible to use factories to build a model with relations? I am currently doing it this way.

$question_data = [
            'question_type' => 32,
        ];
$question = factory(Question::class)->make($question_data);
$questiontext = factory(QuestionText::class)->make();
$question->text = $questiontext;

I was hoping to be able to build it up using the factory itself.