mariohbrino

mariohbrino

Member Since 1 Year Ago

Experience Points 61,620
Experience Level 13

3,380 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 587
Lessons
Completed
Best Reply Awards 4
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.

15 Jul
1 week ago

mariohbrino left a reply on How To Show Count Of All Subject With Slug From Post Table?

Sorry about that the correct relationship.

Subject.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Subject extends Model
{
    /**
     * Get the subjects of post.
     */
    public function posts()
    {
        return $this->hasMany('App\Post');
    }
}

Fetch all results with count

$subjects = App\Subject::withCount('posts')->get();

foreach ($subjects as $subject) {
    echo $subject->posts_count;
}

mariohbrino left a reply on How To Show Count Of All Subject With Slug From Post Table?

You can use eager loading to fetch the data, also you can use counting related models.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    /**
     * Get the subjects of post.
     */
    public function subjects()
    {
        return $this->hasMany('App\Subject');
    }
}

Fetch all results with count

$posts = App\Post::withCount('subjects')->get();

foreach ($posts as $post) {
    echo $post->subjects_count;
}

https://laravel.com/docs/5.8/eloquent-relationships#counting-related-models

mariohbrino left a reply on Pass Array From Child To Parent

You can use props to share data between your child component, also you can use emit event to share the data with your parent component.

<script>
    props: ['source']

    export default {        
        data() {
            return {
                products: this.source
            }
        },

        methods: {
            submit() {
                // ajax request
                this.$emit('save', data);
            }
        }
    }
</script>

Worksheet.vue

<template>
<div>
    <product-cart :source="products" @save="save"/>
</div>
</template>

<script>
    import ProductCart from './ProductCart';

    export default {        
        components: {
            ProductCart
        },

        data() {
            return {
                products: []
            }
        },

        save(data) {
            // do something
        }
    }
</script>

mariohbrino left a reply on Set Radio-button Value By Bool In Array

You can use a current option variable and a watcher to set the value in your array of objects.

new Vue ({
    el: '#app',

    data () {
        return {
            selected: null,
            options: [
                {"id": 1, "title": "Car", "value": false},
                {"id": 2, ": "Bike", ": false },
                {"id": 3,": "Bus",": false},
            ]
        };
    },

    watch: {
      selected(selected) {
        this.options.forEach((option, index) => {
          option.id == selected ? option.value = true : option.value = false;
        });
      }
    }
});
<div id="app">
    <div v-for="(option,index) in options" :key="index">
        <input type="radio"  :id="index" :value="option.id" :name="'option-selected'" v-model="selected">
        <label :for="index">{{option.title}}</label>
    </div>
    {{ options }}
</div>

mariohbrino left a reply on Set Radio-button Value By Bool In Array

I think would be better you have another variable that you set your current option.

Remove the field value in your options and add variable selected.

new Vue ({
    el: '#app',
    data () {
        return {
                selected: null,
            options: [
                {
                        "id": 1,
                        "title": "Car"
                },
                {
                        "id": 2,
                        "title": "Bike"
                },
                {
                        "id": 3,
                        "title": "Bus"
                },
            ],
            };
        },
    });

In input :value change to option.id and the v-model change to selected

<div id="app">
    <div v-for="(option,index) in options" :key="index">
        <input type="radio"  :id="index" :value="option.id" :name="'option-selected'" v-model="selected">
        <label :for="index">{{ option.title }}</label>
    </div>
     {{ selected }}
</div>
23 Apr
3 months ago

mariohbrino left a reply on Tinker Not Working

Which php version are you using?

It can be related about php version 7.3. You can install php version 7.2 or lower and it will work fine.

13 Feb
5 months ago

mariohbrino left a reply on Convert This Query To Eloquent

Here is an example of how you can do this, this is standardized for laravel.

Migrations - designations and employee_details

Schema::create('designations', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->timestamps();
});

Schema::create('employee_details', function (Blueprint $table) {
    $table->increments('id');
    $table->unsignedInteger('designation_id');
    $table->timestamps();

    $table->foreign('designation_id')
        ->references('id')
        ->on('designations')
        ->onDelete('cascade');
});

Models - relationships one to many

class EmployeeDetail extends Model
{
    protected $table = 'employee_details';

    public $fillable = [
        'designation_id'
    ];

    public function designation() {
        return $this->belongsTo(Designation::class);
    }
}

class Designation extends Model
{
    protected $table = 'designations';

    public $fillable = [
        'name'
    ];

    public function employee_details() {
        return $this->hasMany(EmployeeDetail::class);
    }
}

Controller - DesignationController

public function index()
{
    return Designation::select('name')->withCount(['employee_details'])->get();
}

// return [ {"name": "Test', "employee_details_count": 2} , ...]
11 Feb
5 months ago

mariohbrino left a reply on Upload Multiple Images

Follow the link below of article where explain how you can do it.

Medium

mariohbrino left a reply on Pixel Measuring Tool

Yes, it's correct.

You can select a region of the screen by pressing Command–Shift–4 and then holding the cursor pressed while dragging it around. Without releasing the cursor, it makes for a convenient screen ruler that can be opened quickly up at any time. By releasing it you will take a screenshot or you can dismiss it by pressing the Escape key.

Link

04 Feb
5 months ago

mariohbrino left a reply on How Can I Make This Api To Display In The Browser

You can use eloquent relationships. Laravel eloquent relationships

model - add the relationship on your model Property

public function category()
{
        return $this->belongsTo(Category::class);
}

controller - by default laravel return json

public function index()
{
    $property = new Property();
    return $property->with(['category'])->get();
}
03 Jan
6 months ago

mariohbrino left a reply on Artisan Tinker Exit Without Error Message

@bobbybouwmann Thank you, I did find out about it as well.

[link] (https://github.com/laravel/tinker/issues/63 ''Laravel/Tinker Issue")

mariohbrino started a new conversation Artisan Tinker Exit Without Message Error

I was using artisan tinker normally and now it doesn't work any more. I can get inside but on the first command it exit without any message error. Somebody did have this issue before? Any suggestions?

mariohbrino test $ php artisan tinker
Psy Shell v0.9.9 (PHP 7.3.0 — cli) by Justin Hileman
>>> $user = new App\User();
mariohbrino test $ 

Thanks. Regards.

13 Nov
8 months ago

mariohbrino left a reply on Missing Origin Validation In Webpack-dev-server

Any solution on this? I couldn't find a solution yet.

27 Oct
8 months ago

mariohbrino left a reply on Larave Spark To Define Which Users Can Create Team

You need to define where you want to apply the middleware, in this case I did apply into a group middleware web.

You can add the path of your middleware into app/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        \ ------ code above ------
        \App\Http\Middleware\VerifyUserCanCreateTeam::class,
    ],
]
26 Oct
8 months ago

mariohbrino left a reply on Larave Spark To Define Which Users Can Create Team

@Cronix

I found out what was missing from your instructions, thank you.

mariohbrino left a reply on Larave Spark To Define Which Users Can Create Team

@Cronix

I add a field into table users to check if the user can create a team, and use a middleware to set the Spark::noAdditionalTeams, but it doesn't work.

Do you know how can I make it work? Thanks.

if(\Auth::check() && ! $request->user()->join_team && ! Spark::developer($request->user()->email)) {
      Spark::noAdditionalTeams();
}

mariohbrino started a new conversation Larave Spark To Define Which Users Can Create Team

There is a method I can use to define if the user can create teams named noAdditionalTeams, which it can be add at SparkServiceProvider.php to define all users cannot create a team. There is a way to I define which user can create team or cannot?

19 Oct
9 months ago

mariohbrino left a reply on Spark 7.0 Error With Route Model Binding

@Cronix

Thank you.

That worked and is what I needed in the begin. I was thinking and looking for a way to make it generic as well, so I do not have to create a new one for each model. Do you have one idea how to apply to all models?

Thanks.

18 Oct
9 months ago

mariohbrino left a reply on Spark 7.0 Error With Route Model Binding

@Cronix

Thanks, I forget to say that, I saw that before. But, I don't want to do it for each route I have, in case I forget it will be bad.

There is a case when I'll use resource, and this function where is not option for resource routes.

Route

Route::resource('/api/user', 'UserController');

Controller

public function show(User $user) {
    return $user;
}

mariohbrino started a new conversation Spark 7.0 Error With Route Model Binding

I have one issue with Laravel Spark 7.0, the route model binding doesn't abort when it passes a string. It works fine at Laravel 5.7, only in Spark it happens.

Any one can help me with this? Thanks.

Route

Route::get('api/users/{user}', function (App\User $user) {
    return $user->email;
});

Example: app.local/api/user/test

Result

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "test" (SQL: select * from "users" where "id" = test limit 1)
18 Sep
10 months ago

mariohbrino left a reply on How Can I Define A Route That Doesn't Redirect To Team Missing Page

@bobbybouwmann thank you, I did as you suggested, but it keeps happening on redirect me to team/missing. So I noticed that the route was with middleware set by default.

The route web have been set by default the middleware hasTeam, with that in mind I can made my own route admin. Laravel Spark changes the default web route and add a middleware hasTeam. Check the RouteServiceProvider file in app/Providers/RouteServiceProvider.php

protected function mapWebRoutes(Router $router)
    {
        $router->middleware(['web', 'hasTeam'])
               ->namespace($this->namespace)
               ->group(base_path('routes/web.php'));
    }
17 Sep
10 months ago

mariohbrino started a new conversation How Can I Define A Route That Doesn't Redirect To Team Missing Page

When I define the user CanJoinTeams the middleware VerifyUsersHasTeam redirect the user to a team missing, because I don't have a team setup. I want to find a way to bypass the team verification for the admin. Is that possible?

Thanks.

mariohbrino left a reply on Sh: Composer: Command Not Found

I have been install the composer as /usr/local/bin/composer/composer.phar when I should to install /usr/local/bin/composer that's why the alias don't work.

Install and setup composer into /usr/local/bin with name composer

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Add alias into ~/.bash_profile

alias composer="php /usr/local/bin/composer"

13 Sep
10 months ago

mariohbrino left a reply on Sh: Composer: Command Not Found

I did install composer in my macOS 10.13.6 and follow the instructions you guys give, but I still don't have access to composer when I use alias without file composer.phar.

Please, can someone help? Thanks.

  • [x] Install composer
  • [x] Move composer to /usr/local/bin/composer
  • [x] Add alias into ~/.bash_profile
  • [x] Test commands
# Install
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
# Move
mv composer.phar /usr/local/bin/composer

Add alias with file composer.phar into ~/.bash_profile

alias composer="php /usr/local/bin/composer/composer.phar"

Running

composer --version

generates this response

Composer version 1.7.2 2018-08-16 16:57:12

Running

laravel new project-name

generates this response

Crafting application...
sh: composer: command not found
Application ready! Build something amazing.

Change alias without file composer.phar into ~/.bash_profile

alias composer="php /usr/local/bin/composer"

Running

imac server $ composer --version

generates this response

imac server $

Running

cd project-name
imac server $ composer install

generates this response, this don't install any dependencies

imac server $


18 Aug
11 months ago

mariohbrino left a reply on Package Composer Psr-4 Autoload Class Not Found

I found my mistake, my path was wrong.

Wrong: "scr/"

"autoload": {
    "psr-4": {
      "Footer\": "scr/"
    }
  }

Correct: "src/"

"autoload": {
    "psr-4": {
      "Footer\": "src/"
    }
  }

mariohbrino started a new conversation Package Composer Psr-4 Autoload Class Does Not Found

Please can someone help?

I want to make a package test, I did create a composer package dependency. The error message when I import it to my project is Class 'Footer\Foo' not found.

  • Package create test

I did put this dependency into my vendor and run:

    composer dump-autoload

Folder structure

    .
    ├── ...
    ├── vendor
    |   ├── mariohbrino
    |       ├── footer
    |           ├── src
    |               ├── classes
    |                   ├── Whatever.php
    |               Foo.php
    |       ├── composer.json

src\classes\Whatever.php

<?php

namespace Footer\Classes;

class Whatever
{
    public function build(){
        echo 'called';
    }
}

src\Foo.php

<?php

namespace Footer;

use Footer\Classes\Whatever;

class Foo extends Whatever
{
    public function __construct()
    {
        $this->build();
    }
}

composer.json

{
  "name": "mariohbrino/footer",
  "type": "library",
  "description": "Package test",
  "homepage": "http://github.com/mariohbrino/footer",
  "keywords": ["Package", "Test"],
  "license": "MIT",
  "minimum-stability": "dev",
  "authors": [
    {
      "name": "Mario Brino",
      "email": "[email protected]"
    }
  ],
  "require": {
    "php": ">=5.5.0"
  },
  "autoload": {
    "psr-4": {
      "Footer\": "scr/"
    }
  }
}