Jman

Jman

Member Since 1 Year Ago

Experience Points 2,590
Experience Level 1

2,410 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 23
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.

23 May
1 year ago

Jman left a reply on How To Pass Object To View Component?

Thanks @Sirik , however it's passing the model to the component in the view that isn't working; it is fine in the view.

Here is the relevant section in the view edit.blade.php

    {{ html()->modelForm($business, 'PATCH', route('admin.business.update', $business->id))->class('form-horizontal')->open() }}
            @component('backend.includes.partials.businessform', compact('business'))
                Edit
            @endcomponent
    {{ html()->form()->close() }}
@endsection

And in that backend.includes.partials.businessform component, I'm trying to do

<input type="text" class="form-control datepicker"
                               value="{{$business->first_date->format('j\F\Y')}} ">

However I've lost the model object by here. I could do some work with the date with vanilla php but it just seems odd that it should come to this, and surely I'm just doing something wrong here..?

Jman started a new conversation How To Pass Object To View Component?

Hi all,

Amateur questions here...

Short version is: how do I pass a model object to a view component? Not just an array.

Long version is: I have blade views for Create and Edit routes, and they include a form as a Component (so that I need only one form for both functions).

I'm using the spatie html package to map the form with the model, and all was going well until I needed to handle a date. The date is being converted into a carbon object, which is awesome, but it's not setting the date input value when attempting to edit a model. All other input types seem to set their values just fine.

So I thought I'd just use normal html for the input, and set the date value by defining the date format from the model using the carbon date object. However, it seems the model object is not included in the view component by default (odd huh?).

According to the documentation, you can pass data to a component as an array. It doesn't seem to allow passing an object?

It would be great to pass in an object, as I'd like to keep the carbon object in the view component. Is this possible? Or do I have to use a view composer to achieve this?

Thanks!

21 May
1 year ago

Jman left a reply on Middleware Causes Route Note Defined Error..?

Thanks @DevFromRotterdam, that was my initial though but I felt like addressing this at the route level might reduce duplication of logic. However, no harm in starting at the controller and abstracting later if/when needed. Thanks!

18 May
1 year ago

Jman left a reply on Middleware Causes Route Note Defined Error..?

@biishmar I think you're right there, thanks, I'll look into that.

For future reference I'd still be interested in knowing where I went wrong with this one.

Cheers!

Jman started a new conversation Middleware Causes Route Note Defined Error..?

Hi all,

I'm working with Middleware for the first time and hit an issue I can't figure out.

I have users, and users can have a business. Naturally, I don't want users editing each others businesses by manually entering the business id in the url. Middleware seems like the right approach here. However, when I add the middleware to the route, I get an error saying that a route that is used in the view (the destination for the form in the edit view) is not defined. Which is incorrect, because it is correctly named and works just fine when I remove the '->middleware()' call.

The confusing thing is, I'm using a debugger and I can't seem to get it to hit the breakpoint I've set in the middleware. And if I 'dd($business)' in the view, when using the Middleware, it seems the '$business' variable is null, but without the Middleware the model is correctly assigned.

Completely lost, and I can't seem to narrow this one down any further...

Any ideas?

Route ''' /**

  • Frontend Controllers
  • All route names are prefixed with 'frontend.'. */ Route::get('business/{business}/edit', '[email protected]')->name('business.edit')->middleware('verify_business_owner:'.$business->id); Route::patch('business/{business}', '[email protected]')->name('business.update'); '''

Kernel.php ''' protected $routeMiddleware = [ 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'password_expires' => \App\Http\Middleware\PasswordExpires::class, 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class, 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class, 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verify_business_owner' => \App\Http\Middleware\VerifyBusinessOwner::class ]; '''

Middleware ''' namespace App\Http\Middleware;

use Closure; use App\Models\Business;

class VerifyBusinessOwner { /** * Handle an incoming request. * @todo improve check with function in model

 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle($request, Closure $next, Business $business)
{
    $response = $next($request);

    $user = $request->user();
    if($business->user_id != $user->id){
        return redirect('home');
    }

    return $response;
}

} '''

26 Nov
1 year ago

Jman started a new conversation Design Approach Question - Handling Model Parameters Like "status"

Hi Artisans,

This has probably need covered before however I can't even begin to think about what to type in the search bar.

I'm trying to get my head around what would be best practice for handling models that include parameters like "status". For example, let's assume there is a model for "Post", and that Post could have a status of Archived, Published etc...

In the past I have simply used the string. So for example $post->status = "Published" However this get's messy should a new status be introduced, or when parsing in a way that changes the case. I've then gone to using an index, so for example $post->status = 2 However this quickly becomes difficult to read and I forget what values equal what statuses.

Furthermore, I like to use colored-labeling and icons to indicate a status, so I find myself running ugly conditionals to check for a status (either by name or ID) and set a relevant class or icon name.

I am now thinking about setting up a new table and relationship for parameters such as this, which could include the id, the name, an icon, and maybe a class too. But before I do, I thought I'd check in with those more experienced to see what existing solutions might be and if there was a more elegant laravel solution.

Many thanks in advance,

Jamie

14 Nov
1 year ago

Jman left a reply on Model Is Saving But Not Updating!?

Good point re the first sortBy.

I tried the ->load() function out of curiosity, but it didn't seem to work

$steps = $story->load('steps')->sortBy('order')

But I'm probably doing that wrong...

Cheers

Jman left a reply on Model Is Saving But Not Updating!?

Brilliant! Thanks so much that worked a treat!

Jman started a new conversation Model Is Saving But Not Updating!?

Hi all,

I'm adding an item to my model via ajax, however when I attempt to return the updated collection, the new item is not included. I know it was correctly added as it is retrieved on page reload, but I'm trying to get this via ajax. Anyone know what I'm missing here?

    public function create(Story $story)
    {
        $steps = $story->steps->sortBy('order');
        $count = $steps->count();

        $step = new Step;
        $step->order = $count+1;
        $step->normal = true;
        $step->story_id = $story->id;
        $step->description = "new step";
        $step->save();

        //attempt to refresh before return
        $steps = $story->steps->sortBy('order'); //this returns the old collection
        $steps->fresh(); //this seems to do nothing
        return $steps;
    }

Thanks!

Jman left a reply on Refresh A View After Inserting A New Instance Of A Model

I don't understand the question sorry, not sure it that's why no one else has answered. It seems like it should be there if you have updated one and are refreshing the page... surely you are retrieving the full list on reload?

05 Nov
1 year ago

Jman left a reply on How To Use Provided Example.vue?

Hi, I think this needs to be updated.

I'm trying to use Vue in Laravel 5.5 and these instructions don't work for me, nor seem accurate as some IDs have changed. I've watched all the casts on using Vue however Jeffery always just uses the CDN link, which is easy to follow but seems to defeat the purpose of webpack (which always defeats me).

I haven't touched anything related in my install.

In my blade template I have

<div id="app"><example></example></div>
<script src="{{ asset('js/app.js') }}"></script>

and in app.js I have

window.Vue = require('vue');
Vue.component('example', require('./components/Example.vue'));

const app = new Vue({
    el: '#app'
});

So, what else is needed? I've done npm run dev but nothing shows up when I load the page.

Thanks in advance!

30 Oct
1 year ago

Jman left a reply on How To Use A NPM Package In Laravel?

Hey all I'm still really stuck on this one. I thought I would try again with the datatables jQuery plugin but I'm still having issues. I've followed the instructions for installing datatables with NPM, verbatim (except for creating my own 'window' parameter as I don't know what that means or what to do with it), and now I get a console error:

Uncaught TypeError: Cannot set property '$' of undefined

Which references some code in the datatables library

this.$ = function ( sSelector, oOpts )

But I can confirm that jQuery is correctly loaded. If I put the initialisation code in the bottom of the app.js doc it won't work, but it will if loaded in script tags on the html doc, so I wonder if there is some counter-intuitive ordering going on in the way it loads (as the bottom of app.js should be compiled at the end). I made sure to place the require() functions for datatables at the end of the boostrap.js doc, and re-compile with every change.

Does anyone know why initialisation code at the bottom of the app.js file won't work, or why I get this error?

What I would love is a detailed guide on actually installing and using a js library with NPM in Laravel.

Honestly, pasting in the links the old way was SOOO much easier that this NPM stuff. I'm trying to figure it out as everyone else seems to like it but I just don't get it and it never works as described.

Thanks in advance.

PS: I gave up on my previous request, I just did that the old non-npm way and it worked mint.

19 Oct
1 year ago

Jman left a reply on How To Use A NPM Package In Laravel?

Hi I'm new to npm and also stuck here. I'm sure this is supposed to be easy but I cannot find a clear step though explanation that works. Basically, how do we use a npm package?

There must be a better way than creating an alternative to laravel mix...?

I am trying to use the jquery slimscroll package in my project and can't seem to get it to work through npm.

  • I installed it as per instructions npm install jquery-slimscroll

  • it is now in the package.json file in the "dependencies" object.

  • I then added it to the bootstrap.js file (after the require('jquery') line by adding. var slimscroll = require('slimscroll'); (I don'tknow if this is how we are supposed to add our npm packages?)

  • I run "npm run watch" and confirmed that "slimscroll" appears in the compiled public/js/app.js file.

However, I have two problems:

  1. The compiled app.js places the code from assets/js/app.js BEFORE the slimscroll package, even though the assets/js/app.js requires the bootstrap.js file right at the top.

  2. Even if I extract the code that invokes slimscroll

$('#inner-content-div').slimScroll();

and place it in the tags AFTER loading the compiled app.js file, I still get the error of

Uncaught TypeError: $(...).slimScroll is not a function

If I check this in the source code in chrome, I can confirm that slimscroll is included/compiled in the app.js file, which is loaded before the tags, which includes my invocation.

I'm at a loss as to why this isn't working? I can probably make this work by downloading the slimscroll file and saving it to resources/assets/js, then adding it to the webpack.mix,js file, but then what's the point in npm?

Any help greatly appreciated!