FrenchFryNinja

FrenchFryNinja

Member Since 2 Years Ago

Experience Points 8,920
Experience Level 2

1,080 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 84
Lessons
Completed
Best Reply Awards 0
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.

03 Jun
3 months ago

FrenchFryNinja left a reply on ReferenceError: $ Is Not Defined Using Mix

If anyone else has this issue, I had to solve it this way:

in bootstrap.js change "window" to "global." Now I don't know why this fixes things, but it does... Please tell me if this is terrible. Otherwise I could never get $ to be recognized:

global.$ = global.jQuery = require('jquery');

05 Jun
1 year ago

FrenchFryNinja started a new conversation Getting All Table Rows As A Query Builder?

I know about ModelName::all(), but that returns a collection. I need to have all of the results returned as a query builder, but can't for the life of me find out how, other than to write something like:

ModelName::where('id', '>=' 0);

Is this the appropriate way to go about it?

EDIT for clarity:

Essentially I'm not sure I knew what I was asking. The end result was a needed a way to get a builder object back with optional user provided parameters, so I could later call ->get() or->paginate(x) on it as needed. Apparently I missed the basics of query builders. Calling Model::query() gets what I needed.

08 May
1 year ago

FrenchFryNinja left a reply on Cached Views Do Not Clear... I Think?

Had to run opcache:clear as root. I was getting a success message with no changes as [email protected] But it was an opcache issue. Thanks for all your help.

07 May
1 year ago

FrenchFryNinja started a new conversation Cached Views Do Not Clear... I Think?

My view states won't reload on after:

php artisan down
git pull xxxx
composer install
// other server config scripts for secuirty
php artisan up

This has happened twice now. Once on dev, another time on test. Completely re-installing from source does nothing as well. I'm moving into production in 2 weeks, and I'm concerned about running updates in the future and not having the changes promulgate prior to the end of the maintenance window.

So I've tried it all:

php artisan view:clear
php artisan cache:clear
php artisan clear-compiled
php artisan config:clear

I've updated opcache to these settings as in this trouble ticket https://github.com/laradock/laradock/issues/355

extension=opcache.so
opcache.enable="1"
opcache.memory_consumption="256"
opcache.use_cwd="0"
opcache.fast_shutdown="1"
opcache.max_file_size="0"
opcache.validate_timestamps="1" // Modify 0 to 1
opcache.revalidate_freq="0" // Add this line

Subsequently I've done systemctl restart httpd and rebooted the server...

Changes are not reflecting.

And check this part out. I've even rebuilt the project by doing rm -rf against the project directory, reloading from git, composer install and still nada. Absolutamente nada.

I'm running CentOS and Apache. And I just don't know where else to look. Any ideas?

03 Apr
1 year ago

FrenchFryNinja started a new conversation Security Scanning

Hello all,

I had found a Laravel plugin that is a security scanner that would do a code scan for common attack vectors, but the composer require failed. I'm curious what people use to scan their applications to check for vulnerabilities before launch?

I've stuck to best practices like not using any direct DB::statement('do things') calls anywhere and stuck to eloquent, kept csrf enforcement, etc.

But I'm human. I miss things. I want to make sure that I can find them early.

Environment: CentOS 7, Apache, PHP 7+, Laravel 5.6

08 Mar
1 year ago

FrenchFryNinja left a reply on Get The Collection Behind A Paginator Object

Okay, so a paginator pulls the page number from the URL and then defines its offsets that way?

That makes sense now. Thank you. As I said in my initial post, I had a fundamental misunderstanding somewhere. Now its clear.

FrenchFryNinja left a reply on Get The Collection Behind A Paginator Object

@jlrdw Thanks. That's basically what I'm doing now. Just taking a step back and wrapping the QueryBuilder in a different function and calling that from both endpoints. Which is totally workable.

I guess the question remains, though, is it possible to access the raw query from a Paginator? I guess it doesn't make sense to me how it works if this data is not kept somewhere and I'm having trouble finding it in the source.

FrenchFryNinja left a reply on Get The Collection Behind A Paginator Object

Thank you, this is helpful. Is there a way to extract the underlying QueryBuilder or some object from the paginator?

It feels like I'd be repeating myself for no reason to rebuild the query in a different part of the controller.

Or what is a best practice to store the Eloquent QueryBuilder for access later? Via some service provider?

FrenchFryNinja started a new conversation Get The Collection Behind A Paginator Object

I have a pagination object and need to offer the user the ability to download the collection and its associated objects.

Without redoing the query, is there a way to access the LengthAwarePAginator's underlying collection in order to pass it to a method?

For example:

//Complex and time consuming query sets $orderIds
$results = Order::whereIn('id', $orderIds)->paginate(10);
//something like this:
$underlyingCollection = $results->toCollection();

And now I want to be able to call:

XlsFactory::QueryToXls($underlyingCollection);

and be able to access the collection behind the $results object so that I do not have to repeat a time consuming query.

I imagine that the best way it probably to extend LengthAwarePaginator with a custom implementation that will iterate over all pages like this, but all I'm getting is the first collection repeated over the total size of the initial Collection that built the Paginator:

public class MyLengthAwarePaginator extends LengthAwarePaginator
{

public function toCollection()
{
    $results = new Collection();
    $start = $this->currentPage;
    while ( $start++ <= $this->lastPage()) {
        foreach ($this->getCollection() as $item) {
            $results->push($item);
        }
        $this->setCurrentPage($start, $this->pageName);
    }
    return $results;
}

}

Please help. I know I'm missing a fundamental understanding of something here.

22 Nov
1 year ago

FrenchFryNinja left a reply on Trying To Do AJAX Post To Controller Action And Getting An Action Not Defined Or 405 Error

Also, using postman to send a POST request to /orders I'm still getting a MethodNotAllowedException

FrenchFryNinja started a new conversation Trying To Do AJAX Post To Controller Action And Getting An Action Not Defined Or 405 Error

Trying to do an AJAX post. I've hard coded the url to either '/orders' and also used {{ action('[email protected]') }}. The former results in a 405 ajax response and the latter throws an action not defined error and won't load the page.

Here's the web.php:

Route::post('/orders, [email protected]');

There are no other Route::post() that lead to OrderController so no conflict there.

And the AJAX:

$.ajax({
                method: 'POST', 
                url: '/orders',
                data: getOrderJSON(),
                cache: false,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function (response) {
                    console.log(response);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(JSON.stringify(jqXHR));
                    console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
                }
            });

It gets called from a button. Nothing too fancy in the button:

                    <a class="btn btn-outline-red float-right" onclick="processOrder()">Submit Order</a>

I'm really lost here. I've checked the namespacing and its all correct. I've used other methods and they at least work, though the response is essentially gibberish. The page will load. I've done all of these (not necessarily in this order):

composer dump-autoload
php artisan clear-compiled
php artisan cache:clear
php artisan route:clear
php artisan optimize
composer update

And I'm sort of lost here. Everything I've read I have the namespaces correct and the routes file setup correctly, but I'm not able to see the route. Any ideas?

10 Nov
1 year ago

FrenchFryNinja left a reply on Route Model Binding And Fillable In A [email protected] Method

For the time being, if anyone else is happening to use Eloquence there is a short term fix available by adding this to composer until the final fix gets added to the main branch. This will probably be out of date before anyone needs it, but I figured I should include it here anyway:

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/EricTendian/hookable"
        }
    ]

FrenchFryNinja left a reply on Route Model Binding And Fillable In A [email protected] Method

Okay. I figured it out. I was implementing a library called Eloquence in order to make search functionality easier... Apparently this broke Route-Model binding, which in thinking about it makes sense.

So yeah. Now I need to work around that and bug report on the other project.

FrenchFryNinja left a reply on Route Model Binding And Fillable In A [email protected] Method

@shez1983 - I'm not getting an error. Its just not updating. When I do it the iterative way as in the bottom of the original post it works fine (re-lands on the edit page showing updates). Any other way, it doesn't work.

@Snapey - No change.

Do I need to pass EVERY value possible in the fillable field? For example, there's a few items that I'm not sending based on user rules they shouldn't be edited by a standard user. Should these be hidden fields and all values should be contained? Or should route-model binding still work even without all of the fields present?

FrenchFryNinja left a reply on Laravel 5.5 App On Synology DS412+

Make sure your path points to the php7 bin?

FrenchFryNinja left a reply on Route Model Binding And Fillable In A [email protected] Method

This is in the model.

protected $fillable = ['last name',
        'first_name',
        'middle_name',
        'last_name',
        'name_suffix',
        ...
//more relevant fields here
    ];

FrenchFryNinja left a reply on Route Model Binding And Fillable In A [email protected] Method

I've done that and its still not accepting changes in the $patient->update(request()->all()) piece like it should.

FrenchFryNinja started a new conversation Route Model Binding And Fillable In A [email protected] Method

I don't know what I'm doing wrong here. I have a form that submits a patch request to the route and the route given as follows:

Route::patch('patients/{patient}', '[email protected]');

and update method in the controller:


    public function update(Request $request, Patient $patient)
    {
        $patient->update(request()->all());
        return redirect()->action('[email protected]');
    }

dd on request() or $request gives me exactly what I want:

array:12 [▼
  "_method" => "PATCH"
  "_token" => "2KWffXiRGEuBxOdAmfuL9EbBaX4nFilAAJFZhpo4"
  "first_name" => "Wendell"
  "middle_name" => "THE THING I'M CHANGING!"
  "last_name" => "Abernathy"
  "address1" => "846 Waters Plain"
  "address2" => null
  "address3" => null
  "city" => "North Amber"
  "state" => "TO"
  "postal_code" => "78951"
  "email" => null
]

This does not work so I have to manually update every field I want to in body of the update function:

        $patient->middle_name = request()->middle_name;
        $patient->last_name = \request()->last_name;
 .... etc.

Is there a faster way of doing this where I can reference the fillables somehow? I wrapped the protected $fillables with a getter and I'm iterating over the request object for updates like this and that works, but this seems like with all of the other laravel tools that I'm missing something here that should be done for me.

Here's what I'm doing that works:

    public function update(Patient $patient)
    {
        foreach(request()->all() as $key => $value)
        {
            if(in_array($key, $patient->getFillables())){
                $patient->$key = $value;
            }
        }
        $patient->save();
        return redirect()->action('[email protected]');
    }
06 Nov
1 year ago

FrenchFryNinja started a new conversation Eloquent Doesn't See Existing Records

In PHP artisan tinker I've setup some LabTest objects with a factory method. These are linked with TestCategory in a pivot table. All of these tables are generated via migration.

So this: factory(App\LabTest::class, 75)->create()

creates 75 lab tests like expected.

The TestCategory class has a many-to-many relation with LabTest, but I already have the TestCategory data in a database dump file. So I don't need a factory. What I do need to be able to do is populate the pivot table (lab_test_test_category table), but in order to do that I need to be able to query my existing test categories... and I can't. Why is this happening? If I generate them with a factory, I can see them. Why can't I see the data that's already in the database?

I know I can just build a new factory for the TestCategory rather than try and get this to work, and that's what I'm doing so that I can keep working, but its bugging my why its not working. can anyone help? I'm still pretty new to Laravel.