quickliketurtle

quickliketurtle

Member Since 5 Years Ago

Experience Points 78,130
Experience Level 16

1,870 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 1001
Lessons
Completed
Best Reply Awards 10
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.

20 Nov
1 year ago

quickliketurtle left a reply on Laravel Not Logging Anyting

This just solved my problem. Working on an oss codebase and could not figure out why I couldn't log anything... Wrapped the bugsnag aliases in the env check and good to go.

Thanks @dubbeltje :-)

30 Jun
2 years ago

quickliketurtle left a reply on Storing Bank Information In The Database

My recommendation is to avoid it at all costs. Offload all that security and compliance to a company that specialized in it. If you do need to store some info start reading up on PCI compliance and what you can and can't store and the implications on compliance level and status. https://www.pcisecuritystandards.org/

29 Jun
2 years ago

quickliketurtle left a reply on Can I Use Laravel 5.5 Now ?

@CodebyRay make sure you have the latest version of the installer. The current version is 1.3.6

When I run laravel new app --dev, then run php artisan --version I get Laravel Framework 5.5-dev

28 Jun
2 years ago

quickliketurtle left a reply on Can I Use Laravel 5.5 Now ?

You can pass the --dev flag to the laravel installer to get dev-master branch.

laravel new app --dev
27 Jun
2 years ago

quickliketurtle left a reply on Learning Laravel Testing

Take a look at the docs: https://laravel.com/docs/5.4/testing https://laravel.com/docs/5.4/http-tests https://laravel.com/docs/5.4/dusk

Basically, there is the 'built' in helpers for running tests. https://laravel.com/docs/5.4/http-tests The equivalent of running $this->visit() would be $this->get() and inspecting the response.

Or for browser testing, there is Laravel Dusk that will open a browser and view the rendered results for example.

I'd suggest starting without Dusk, and getting the basics first. Then adding Dusk to your test suite only if you need that additional function.

quickliketurtle left a reply on What To Keep In Mind In The Controller When Dealing With Ajax?

@chriz74 An example use case may be that you are using the same endpoint for both browser and api calls. So you want to return a view for the browser call and json for the api call.

public function show(User $user) {
    
    // request wants json
    if($request->ajax()) {
        return $user;
    }

    // not ajax call so return view
    return view('user.show', compact('user');
    
}   

quickliketurtle left a reply on Validation Rules Abstraction

Hello, since you are storing the $rules and $messages properties on the controller, you would need to refer to them with $this

$validator = Validator::make($request, $this->rules, $this->messages);

Another option would be form requests. https://laravel.com/docs/5.4/validation#form-request-validation

A sort of middle option would be to store the rules and messages right on the model you are validating.

quickliketurtle left a reply on Creating Your Own Webhook

Check this video: https://laracasts.com/series/how-to-accept-payments-with-stripe/episodes/9 Talks about webhooks with strips. May be helpful.

quickliketurtle left a reply on Three-way Pivot Table

Why is tracking this in one table a requirement?

It sounds to me like the relationships would be a surgery has many tasks and a task belongs to a surgery. A task belongs to a user and a user has many tasks.

Take a look at this for an example that might be similar to your use case: https://laravel.io/forum/08-06-2014-three-way-pivot-table-with-eloquent

quickliketurtle left a reply on Session Data

Generally, session cookies are stored in browser specific storage so they are not accessible between browsers.

26 Jun
2 years ago

quickliketurtle left a reply on Importing Boolean Columns With Maatwebsite/excel

@squibby From the doc's http://www.maatwebsite.nl/laravel-excel/docs/import

Custom formatting values

By default Laravel Excel uses PHPExcel's default value binder to intelligently format a cells value when reading it. You may override this behavior by passing in your own value binder to suit your specific needs. Value binders must implement PHPExcel_Cell_IValueBinder and have a bindValue method. They may also extend PHPExcel_Cell_DefaultValueBinder to return the default behavior.

use PHPExcel_Cell;
use PHPExcel_Cell_DataType;
use PHPExcel_Cell_IValueBinder;
use PHPExcel_Cell_DefaultValueBinder;

class MyValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{
    public function bindValue(PHPExcel_Cell $cell, $value = null)
    {
        if (is_numeric($value))
        {
            $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_NUMERIC);

            return true;
        }

        // else return default behavior
        return parent::bindValue($cell, $value);
    }
}

$myValueBinder = new MyValueBinder;

$reader = Excel::setValueBinder($myValueBinder)->load('file.xls');
// Reader methods
Available PHPExcel_Cell_DataType's are TYPE_STRING, TYPE_FORMULA, TYPE_NUMERIC, TYPE_BOOL, TYPE_NULL, TYPE_INLINE and TYPE_ERROR

To reset the value binder back to default and/or before calling Laravel Excel after setting a custom value binder you need to call the resetValueBinder method.

Excel::resetValueBinder();
25 Jun
2 years ago

quickliketurtle left a reply on Homestead: Unable To Connect With MySQL Workbench To MySql Database

@maxluzon your mysql host should be the homestead vm's ip (192.169.10.10) as @agapito78 said. Are you sure the ssh key you reference is setup on the homestead vm?

quickliketurtle left a reply on Vue Data Parent Reference Inside Data Field

Hello, I believe this has to be with you trying to access the dataVar object inside the dataVar object.

You can instead do something like this:

    dataVar = new function() {
            this.id = "1",
            this.moreData = {
                phoneNum: "1231231239",
                stuff: "two"
            },
            this.header = "Insert",
            this.instructions = [
                {
                    title:"title1",
                    content: "Call the number " + this.moreData.phoneNum + " and then contiune the other instructions."
                },{
                title:"title1",
                content: "Another instruction"
                }
            ],
            this.NIP = 0
        };

You also need to add dataVar inside Vue's data object:

    new Vue({
        el: '#app',
        data: {
            dataVar
        }
    });
23 Jun
2 years ago

quickliketurtle left a reply on Image Blob Malformed UTF-8 Characters, Possibly Incorrectly Encoded

@derrickrozay I was thinking Content-type: image/jpg but that probably won't work either.

I'm thinking it's related to JSON needing only UTF8 chars and your blob may have invalid chars. Try utf8_encode($pic). http://at2.php.net/manual/en/function.utf8-encode.php

quickliketurtle left a reply on Image Blob Malformed UTF-8 Characters, Possibly Incorrectly Encoded

@derrickrozay Try adding a content-type header to your response.

quickliketurtle left a reply on Use Axios / Ajax To Send File And Other Data Without FormData?

@ricardoarg Right sorry, axios doesn't stringify by default.

Check out this issue: https://github.com/mzabriskie/axios/issues/318 Could be related to the content-type header, or needing to stream the file into the form object.

quickliketurtle left a reply on Image Blob Malformed UTF-8 Characters, Possibly Incorrectly Encoded

@derrickrozay Can you post your code to store and retrieve the image?

quickliketurtle left a reply on Use Axios / Ajax To Send File And Other Data Without FormData?

@ricardoarg Use json_decode() on the server side to convert the data back to its original data type.

quickliketurtle left a reply on Migration Error

@BarthFox I don't see the code. Can you paste it in a code block?

quickliketurtle left a reply on Log Every Request & Response

Default location is /storage/logs/laravel.log

quickliketurtle left a reply on Wrapping Validation Errors In 'data'

You can create a custom validator to accomplish this. Here is an example:

$app->post('/user', function (Request $request) {
    $validator = Validator::make($request->all(), [
        'name' => 'required',
    ]);

    return response(
        ['data' => $validator->messages()]
    );
});

Use Validator::make and pass the request and rules. Then you can return your response and wrap the messages however you want. In the example above the response is:

{
    "data": {
        "name": [
            "The name field is required."
        ]
    }
}

Note in order to use the Validator facade you need to uncomment $app->withFacades(); in your bootstrap/app.php file.

22 Jun
2 years ago

quickliketurtle left a reply on MethodNotAllowedHttpException

I'd expect you have a route Route::post('/post', '[email protected]'); so your form action should be action="post". Then when you submit the form you are calling the store method on the PostsController.

Or maybe you are trying to call a named route in which case your form action needs to use the route helper to get the path. action="{{ route('post.store') }}"

quickliketurtle left a reply on Laravel Mix Suddenly Stopped Working

@JohnnyL Does it compile if you run npm run dev?

quickliketurtle left a reply on Required Without All Validation

@douglas_quaid What did you come up with?

I created this collection macro:

Collection::macro('mergeAppend', function ($collection, $seperator = '|') {
    $collection = collect($collection);

    return $this->map(function ($value, $key) use ($collection, $seperator) {
        if ($collection->has($key)) {
            return $value . $seperator . $collection->get($key);
        }

        return $value;
    });
});

So you could do something like this:

$fields = collect(['field1', 'field2', 'field3', 'field4', 'field5']);
    $oldRules = ['field1' => 'required', 'field3' => 'required'];

    $newRules = $fields->mapWithKeys(function ($field) use ($fields) {
        return [
            $field => 'required_without_all:' . getExcept($fields, $field)
        ];
    })->mergeAppend(collect($oldRules));

    dd($newRules->toArray());

The result would be:

[
  "field1" => "required_without_all:field2,field3,field4,field5|required"
  "field2" => "required_without_all:field1,field3,field4,field5"
  "field3" => "required_without_all:field1,field2,field4,field5|required"
  "field4" => "required_without_all:field1,field2,field3,field5"
  "field5" => "required_without_all:field1,field2,field3,field4"
]

quickliketurtle left a reply on Migration Error

@barthfox Can you reply with the code from your migration file, please?

quickliketurtle left a reply on How To Access Image From Storage File

@gbolade We can't see your blade file. Can you add the code in a code block to your post?

Your 'picture' key in your array will be the path to the image. Assuming you are trying to create an image tag in your view you can do something like:

<img src="{{asset($picture)}}">
21 Jun
2 years ago

quickliketurtle left a reply on Required Without All Validation

Hello, I'm not aware of being able to pass anything but the string you provided.

I did play around with dynamically creating the strings though. Not sure if it fits your use case or not.

Basically, start with a collection of your fields, you could get these from the model or something but I just hard coded them here. Then you map over the collection to create a new collection with the field as the key and the value as you described.

$fields = collect(['field1', 'field2', 'field3', 'field4', 'field5']);

$rules = $fields->mapWithKeys(function ($field) use ($fields) {
    return [
        $field => 'required_without_all:' . getExcept($fields, $field)
    ];
})->toArray();

To get the list of fields minus the current field I made a getExcept function that takes the collection, and the field that should not be returned and returns a comma separated list of the remaining fields.

function getExcept($collection, $exception) {
    return $collection->reject(function ($item) use ($exception) {
        return $item == $exception;
    })->implode(',');
}

Not sure this is worth it if you only have a handful of fields, even though typing them out is tedious. But it was fun to figure out. :-)

If I were going to use this I'd take a step further and wrap it in a function called createRulesArray and maybe accept the rule type so you could build other rules as well. But again not sure it's worth it.

quickliketurtle left a reply on Updating And Creating Records

In that case, you should be able to check if the profile exists with the relationship. No need for a boolean on the user model.

if ($user->profile) {
    // user has a profile
}

As for re-using the same form for both creating and editing the profile. Here is an older laracasts vid but it should still be relevant: https://laracasts.com/series/laravel-5-fundamentals/episodes/13

quickliketurtle left a reply on Laravel + Instagram

@cleopatra Sure you can. It's just js at that point. Really no Laravel specific thing there. You would just include it however you are using other js files.

20 Jun
2 years ago

quickliketurtle left a reply on Laravel + Instagram

vinkla/instagram requires php: ^7.0 which explains the error you are getting.

With your second xampp instance run php -v to make sure it is using v.7 on the command line.

quickliketurtle left a reply on How To Generate Pdf Wtih Japanese Font With Barryvdh/laravel-dompdf

@chask This isn't related to Laravel but specific to dompdf.

Is the font you want to use available online? If is was say a google font, then you could use css to style your page.

Using @import

<style>
@import url('https://fonts.googleapis.com/css?family=Roboto');
</style>

And style your page with font-family: 'Roboto', sans-serif;

Or alternatively using @font-face

@font-face {
  font-family: 'Firefly';
  font-style: normal;
  font-weight: normal;
  src: url(http://example.com/fonts/firefly.ttf) format('truetype');
}

If your font is not available from a url. Then your other option would be to load it into dompdf from the command line.

You would need to install the load_font.php script from https://github.com/dompdf/utils More info can be found here also: https://github.com/dompdf/dompdf/wiki/UnicodeHowTo#load-a-font-supporting-your-characters-into-dompdf

quickliketurtle left a reply on Model Get Method Uses Json_decode Twice

You would use JSON.stringify($shipping) on the client side before making your ajax request. Then json_decode(request('shipping')) on the server side.

quickliketurtle left a reply on Model Get Method Uses Json_decode Twice

I'm not able to duplicate your issue with a fresh project. But what I can tell you is that if you are saving an array to the DB, then you should not have double quotes sounding it in the DB.

The field itself in the DB is a text field. What you should see if you look at the DB directly is just

[{"id":"1","country":"New Zealand","shipping_rate":"1"},{"id":"2","country":"Australia","shipping_rate":"2"}]

This will be returned as a string and since you are casting it to json with the $casts property in the model you don't need your getter.

However, if the entry in the DB includes double quotes

"[{"id":"1","country":"New Zealand","shipping_rate":"1"},{"id":"2","country":"Australia","shipping_rate":"2"}]"

Then the string that is returned includes 2 sets of double quotes.

Sorry that's not more helpful.

Also unrelated but you can re-write your getter as:

public function getShippingAttribute($value)
{
    return $value ? json_decode($value) : [];
}

Since the getter is passed the value you can reference it directly.

19 Jun
2 years ago

quickliketurtle left a reply on Model Get Method Uses Json_decode Twice

@kdm Thanks for the details. I'll stub out a new app with these details and see what I can figure out. I'm guessing it has to do with all the casting back and forth from json to string to json to array...

Will let you know what I find shortly.

Thanks.

quickliketurtle left a reply on Updating And Creating Records

Hello, In your case is the user's profile part of the User object? Meaning you just added some fields to the user's table?

Or did you create a separate profile table?

There are a few options depending on the user experience you want / your goals.

Without knowing more I might do something like adding the additional fields to the registration form so new users fill them out when creating an account.

Then logged in users would have an edit profile link that would load a form pre-filled with their existing data.

As for the routes check out this: https://laravel.com/docs/5.4/controllers#resource-controllers for a good example.

Let me know some more details and I can give more specific examples.

Thanks.

quickliketurtle left a reply on How To Generate Pdf Wtih Japanese Font With Barryvdh/laravel-dompdf

Easiest is if the font is available online. Then you would just @import it in your CSS.

That and some other options are in listed here: https://stackoverflow.com/questions/24412203/dompdf-and-set-different-font-family

quickliketurtle left a reply on Model Get Method Uses Json_decode Twice

Hello, If I run json_decode() on your above string i get an array with 2 objects as expected so the text in the db seems fine.

It looks like 'shipping' is the field in the db, How are you adding that to the attributes array?

What's the type/value of attributes['shipping']? Is that the exact text in the db or is that getting wrapped in another string or array or something?

quickliketurtle left a reply on How To Redirect The User Back To The View With Error When The Controller Return Exception?

@malhayek Either use the full namespace \Illuminate\Database\QueryException as @mushood said above or make sure you are importing it at the top of your controller use \Illuminate\Database\QueryException; That should get you catching the exception so you can move on to debugging the redirect.

17 Feb
3 years ago

quickliketurtle left a reply on Changing Default Connection In Run Time

My thought would be that settings are loaded when the app boots, and are not refreshed for each page load.

quickliketurtle left a reply on Updating Table In Controller

Since the DB::listen call is temporarily you can just add it to the top of your routes.php file. Or you can just add it right above your save code.

public function update() 
{
    \DB::listen(function($sql) {
            var_dump($sql);
    });

    $plan = Plan::find($id);
        $plan->timestamps = false;
        $plan->incrementing = false;
        $plan->plesk_sub_id = '123456';
        $plan->save();
}

quickliketurtle left a reply on Using UpdateOrCreate() With Incrementing Value

Eloquent has both a findOrCreate and findOrNew method.

// Retrieve the flight by the attributes, or create it if it doesn't exist...
$flight = App\Flight::firstOrCreate(['name' => 'Flight 10']);

// Retrieve the flight by the attributes, or instantiate a new instance...
$flight = App\Flight::firstOrNew(['name' => 'Flight 10']);

Maybe that will help? https://laravel.com/docs/5.2/eloquent#inserting-and-updating-models

--Jeff

16 Feb
3 years ago

quickliketurtle left a reply on Changing Default Connection In Run Time

If you get the config after redirecting, does it show the updated database default?

\Config::get('database.default');

Maybe the config change is saving but the Auth class is not picking up the change...

--Jeff

quickliketurtle left a reply on Updating Table In Controller

Hello - To disable timestamps you should set them to false in the Plan model.

public $timestamps = false;

You can add something like this to the method so you can see the query that is being executed to see if it's what you expect:

\DB::listen(function($sql) {
    var_dump($sql);
});

--Jeff

quickliketurtle left a reply on L5.2 Elequent Relationships - Really Struggling On This :(

I re-created your example and was able to duplicate the errors. I think some of the issue may be naming conventions. Laravel is expecting Models to be singular (User, Order) which will assume db tables are plural (users, orders).

In this case of Orders belonging to Users in the Orders class we would create:

function user()
{
    return $this->belongsTo('App\User');
}

Laravel will assume a foreign key (in the orders table) of user_id.

Then you reference the relationship like:

$order->user->name;

In this case owner is a better name for the relationship i think so we can call the function owner, but then Laravel will assume a foreign key of 'owner_id' so we need to override that by passing a second parameter of 'user_id'

public function owner()
{
    return $this->belongsTo('App\User', 'user_id');
}

As an aside calling $order->owner() will return the relationship itself where as $order->owner will return the object.

Hope this explanation is useful. I learned a bit writing it out. :-)

Thanks. --Jeff

quickliketurtle started a new conversation How Do You Include Files From Node_modules In Elixir?

How do you include files from node_modules in elixir?

  1. Copy file to assets folder first? Like scss example.
  2. Reference file directly in node_modules directory? Like js example.
  3. Something else entirely?
var elixir = require('laravel-elixir');

elixir(function(mix) {
    mix.copy('node_modules/sweetalert/dist/sweetalert.css', 'resources/assets/sass/sweetalert.scss');

    mix.sass('app.scss')
        .version('css/app.css');

    mix.scripts([
        '../../../node_modules/sweetalert/dist/sweetalert.min.js'
    ], 'public/js/app.js');
});

Let me know how your are doing it.

Thanks. --Jeff

12 Sep
4 years ago

quickliketurtle left a reply on The New Way To Submit Laravel Bug Reports

@valorin Thanks, looks like your right with the curl bug.
I'm having a dumb moment and can't figure out how to update... I'm running osx 10.10, brew doesn't have the update yet, and macports install is for 10.9.