chrisan

chrisan

Member Since 2 Months Ago

Experience Points
4,260
Total
Experience

740 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
40
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 1
4,260 XP
Mar
27
1 week ago
Activity icon

Replied to What Is The Best Way To Authorize A Create Policy Depending On Value Of A Field?

Thanks for the reply, but ya unfortunately the admins can administer multiple companies (which are almost always different retails brands of the same parent company) so they do get a limited dropdown of companies they should be able to manage and thus company_id is in post data.

I guess I could make /users a sub-resource of /companies /companies/123/users

Mar
26
1 week ago
Activity icon

Started a new Conversation What Is The Best Way To Authorize A Create Policy Depending On Value Of A Field?

Say we have a user manager. Super admins can do anything. Admins can only manage users of their company.

The admin can create a new user or new admin, but I only want them to create a new user if the new user is also set to a company they manage.

Right now I am running authorize on the store method after validation and before the model is created/saved

$this->authorize('create', [User::class, $validatedAttributes['company_id']]);

Which checks against this policy

public function create(User $user, int $company_id) {
  if (in_array($company_id, $user->companyIds())) {
    return Response::allow();
  }
  else {
    return Response::deny('You are not allowed to manage this company');
  }
}

Where it will fail if they maliciously try to alter the form and create a user in another company.

Am I headed down the right path or should I be looking at something else to use? It works... but it "felt" kinda weird so I wasn't sure if I'm following the "Laravel way"

Mar
23
1 week ago
Activity icon

Replied to Multiple Domain Single Application

Ah, looks like you need to add a pattern in boot() for the RouteServiceProvider

public function boot()
{
  Route::pattern('domain', '[a-z0-9.\-]+');
  parent::boot();
}
Mar
22
1 week ago
Activity icon

Replied to Multiple Domain Single Application

This doesn't appear to work in Laravel 6.x. Is it a 7.x feature?

If you edit your hosts file and point a couple dummy domains at your server

127.0.0.1 test.local
127.0.0.1 test.com
127.0.0.1 sub.test.local
127.0.0.1 test.localhost

with your code

Route::domain('{domain}')->group(function() {

  Route::get('/', function($domain) {
    // controller logic
    dd($domain);
  });


  Route::get('/user/{user}', function($domain , $user) {
    // something else
  });

});

routes:

 $ php artisan route:list
+----------+----------+-------------+------+---------+--------------+
| Domain   | Method   | URI         | Name | Action  | Middleware   |
+----------+----------+-------------+------+---------+--------------+
| {domain} | GET|HEAD | /           |      | Closure | web          |
|          | GET|HEAD | api/user    |      | Closure | api,auth:api |
| {domain} | GET|HEAD | user/{user} |      | Closure | web          |
+----------+----------+-------------+------+---------+--------------+

Only localhost gets dumped, every other domain gets sent to 404 when using php artisan serve --host=0.0.0.0

Any ideas?

Feb
26
1 month ago
Activity icon

Started a new Conversation Is There A Max Size For Forms And Validation Via Session Flash?

I have a lengthy form, about 40-50 flags for a model we store in the database.

As I was adding fields I noticed my errors stopped appearing sometime during development of this form using this to output the errors:

@if ($errors->any())
  <div class="alert alert-danger">
    <ul>
      @foreach ($errors->all() as $error)
        <li>{{ $error }}</li>
      @endforeach
    </ul>
  </div>
@endif

I thought typo or some other logic and kept removing fields one by one and then it worked again. OK, so back to working form an errors showing. I add 1 more field and poof, no more errors show.

Here is the controller, nothing special

public function update(Request $request, Company $company) {
//    try {
  $validatedAttributes = $request->validate([
    'name' => ['required','max:255'],
    'key' => ['required','max:255'],
    'active' => ['required', 'boolean'],
    'tracking' => ['required']
  ]);
//    }
//    catch (\Exception $e) {
//      dd($e);
//    }

  $company->update($validatedAttributes);
  $this->flash('success',$company->name . ' was updated!');
  return redirect(route('companys.edit', $company));
}

Now when I enable the try catch, the errors show up in the dump. But they never make it to the flashed session

If I delete the new field again, then again errors show.

I add different "one more" field, and surprise, errors back.

The fields are exactly the same except for their names. Here is an example

<label class="col-sm-2 col-form-label" for="foo_bar_baz_qux_qwerty">Sale Price</label>
<div class="col-sm-4">
  <select name="foo_bar_baz_qux_qwerty" id="foo_bar_baz_qux_qwerty" class="form-control m-b">
    <option value="foobar">foobar</option>
  </select>
</div>

OK so 1 field works but the other doesn't. Its all the same format.

I take the working field and rename it to the last field that made errors go away. Try again and yup, errors are gone.

Extremely baffled I now remove a character from the name 1 letter at a time and somewhere through it errors appear again.

I further test and put the name back to original and then remove characters from the value of the select and again suprise, errors gone again.

I seem to have hit some hard limit on the error object. The above field DOES NOT work. But EITHER of these 2 fields will work: first a shorter name foo_bar_baz_qux_qwert OR a shorter value fooba in the second example

shorter name:

<label class="col-sm-2 col-form-label" for="foo_bar_baz_qux_qwert">Sale Price</label>
<div class="col-sm-4">
  <select name="foo_bar_baz_qux_qwert" id="foo_bar_baz_qux_qwert" class="form-control m-b">
    <option value="foobar">foobar</option>
  </select>
</div>

shorter value:

<label class="col-sm-2 col-form-label" for="foo_bar_baz_qux_qwerty">Sale Price</label>
<div class="col-sm-4">
  <select name="foo_bar_baz_qux_qwerty" id="foo_bar_baz_qux_qwerty" class="form-control m-b">
    <option value="fooba">foobar</option>
  </select>
</div>

So now I think I have some kind hard limit on the total size for all names + values.

I guess I will split this form up into tabs so theres only 10-20 fields per tab, but is anyone aware of such a limit with the validation object?

Jan
26
2 months ago
Activity icon

Commented on Integrate A Site Template

"Extend Selection" in PhpStorm

Activity icon

Replied to Log File Permission Problem

I've always used ACL when having to deal with the local user who 'owns the app' and the web server user

Assuming your webserver user runs as www-data I run this on my local linux user

setfacl -d -R -m u:$USER:rwx -m g:www-data:rwx storage/   
setfacl -d -R -m u:$USER:rwx -m g:www-data:rwx bootstrap/cache/
Jan
24
2 months ago
Activity icon

Replied to Migrating Old PHP To Laravel, App.js Is Double Original Size

Thx! I am running npm run prod however based on what you said it looks like packages have changed (increased) since this theme was created. The old site is using some older versions (no locales in moment for example) so I guess I'll run through each of these 1 by 1 to see how much they have increased

But still, even commenting out everything but jquery I am left with an 87.2KB app.js while jquery 3.4 https://code.jquery.com/jquery-3.4.1.min.js is 30.4KB

Is there something else going on perhaps?

edit: nevermind, I just noticed php artisan serve does not use gzip! that is probably where the remaining size is coming from

Activity icon

Started a new Conversation Migrating Old PHP To Laravel, App.js Is Double Original Size

I've got a plain old PHP app with a bunch of script tags (no build tools) we are converting to Laravel

Here is the network monitor of the old app loading:

old js load

141.8 KB

After running npm run build my app.js is 307KB and I'm confused where the size is coming from

app.js

require('./bootstrap');
require('./inspinia');  // theme javascript copied from old project

bootstrap.js

// window._ = require('lodash');

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');
    window.moment = require('moment');

    require('bootstrap');
    require('jquery-slimscroll');
    require('dom4');
    require('tempusdominus-bootstrap-4');
    require('chart.js');

} catch (e) {}

/**
 * We'll load the axios HTTP library which allows us to easily issue requests
 * to our Laravel back-end. This library automatically handles sending the
 * CSRF token as a header based on the value of the "XSRF" token cookie.
 */

// window.axios = require('axios');
//
// window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

/**
 * Echo exposes an expressive API for subscribing to channels and listening
 * for events that are broadcast by Laravel. Echo and event broadcasting
 * allows your team to easily build robust real-time web applications.
 */

// import Echo from 'laravel-echo';

// window.Pusher = require('pusher-js');

// window.Echo = new Echo({
//     broadcaster: 'pusher',
//     key: process.env.MIX_PUSHER_APP_KEY,
//     cluster: process.env.MIX_PUSHER_APP_CLUSTER,
//     encrypted: true
// });

package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.19",
        "bootstrap": "^4.0.0",
        "chart.js": "^2.9.3",
        "cross-env": "^5.1",
        "dom4": "^2.1.5",
        "jquery": "^3.2",
        "jquery-slimscroll": "^1.3.8",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.13",
        "metismenu": "^2.7.9",
        "moment": "^2.24.0",
        "popper.js": "^1.12",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "tempusdominus-bootstrap-4": "^5.1.2",
        "vue-template-compiler": "^2.6.11"
    },
    "dependencies": {
    }
}

Anywhere else I should be looking to trim this back down?