lirone

lirone

Member Since 3 Weeks Ago

Experience Points
3,580
Total
Experience

1,420 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
33
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
3,580 XP
Jul
09
1 day ago
Activity icon

Replied to Passing Javascript Variable To Component Laravel 7

Thank for your answer ! I will take a look on livewire !

Otherwise, I think it gonna be painful to create all my html block from scratch using only JS.

Activity icon

Started a new Conversation Passing Javascript Variable To Component Laravel 7

I'm fetching data from Ajax after sending a form.

The data is composed of multiple products. I would like to display all those product in a beautiful way in my html page. For that, I need to loop over my product, create HTML block then add to a div.

I was thinking of using a component to simplify the process.

However, the way I'm passing the data is not working.


var products= fetchData(url);

var htmlBlock = `
            <x-products-chart :products="${products}">
            `;

 $('.results-products').append(htmlBlock);

Do you have any suggestions for doing that ?

Jul
08
2 days ago
Activity icon

Started a new Conversation Managing Group's Product

Hi,

I have implemented groups with permission. Each group has access to its own products. I have a table with all my products. I have a table that is the link between my products and the groups

product_group product_id group_id

When an user is connecting to the dashboard, I would like him to see only the products that are belonging to its group.

I have the methods implemented that are looking for products that belong to an user/group.

My question is : what is the best way to filter products based on the group ? I was thinking to get the ID of the group on each of my controller and then call the method with the appropriate group id. However, I will have many repetition.

Thank in advance

Jul
01
1 week ago
Activity icon

Replied to Get User's Record Via Model ?

Thank for your answer ! What do you suggest for methods ? Put everything in my user repo or each method its according repo (RecordA and RecordB) ?

Jun
30
1 week ago
Activity icon

Started a new Conversation Get User's Record Via Model ?

I'm starting learning Laravel and I wonder about the way to retrieve some data. I have 4 tables

  • Users
  • Records
  • RecordsA
  • RecordsB

An Users may have multiple records. (Records has a foreign key of user) RecordsA has a foreign key of Records RecordsB has a foreign key of Records

I would like to retrieve records (A or B) from an User and I wonder what is the best way to do it.

  1. Write functions to the user's repository getRecordA() and getRecordB() so that I could do in my controller, $this->user->getRecordA() and user->getRecordB()

  2. Write functions to recordA's repository and recordB's repository ? So I will inject the id of the user in the query. So in my controller, I could write recordA->get(User $user)

I'm asking that, because the user is the core of my app and I have many tables (among Records, RecordsA and RecordB) that are linked to my user and I'm affraid that my user table will be huge. However, for me it's intuitive to put all the related function to the user repository.

What do you think ? Could you please give the good practice ?

Jun
24
2 weeks ago
Activity icon

Started a new Conversation Make A Restful API For Fetching Data From Database ?

I'm learning Laravel. What I would like to know if fetching data from my database for feeding a map (leaflet JS)

Let's say, I have a table called Location which contains all the location (id, name, latitude, longitude).

So far, what I want to do is the following:

  • Create LocationController
  • Create LocationRepositories that link my controller to my model Location. Inside, I will have the all() method that will fetch all my location rows.
  • In my index function, call the LocationRepositories::all() to fetch the data and pass them to my View.

But I saw that there is another way to do it using axio i.e fetch data from API. For example axios.get('{{ route('api.location.index') }}') For example the url /api/locations would returns a json that contains all my locations data. So this time, my LocationController will be a ressource and I will have a Location API in my API Folder.

What is the recommended way to do things ? Is doing API for fetching data is a better practice ?

Jun
23
2 weeks ago
Activity icon

Replied to Eloquent Multiple Relationship Return Attributes Array

Here the sensor class

<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

class Sensor extends Model
{
	protected $table = 'sensors';
	public $timestamps = false;

	protected $casts = [
		'equipement_id' => 'int',
	];

	protected $dates = [
		'installation_date'
	];

	protected $fillable = [
		'equipement_id',
		'deveui',
	];



	public function equipement()
	{
		return $this->belongsTo(Equipement::class);
	}



	public function pools()
	{
		return $this->hasMany(Pool::class);
	}
	public function records()
	{
		return $this->hasMany(Record::class);
	}

	public function sensor_groups()
	{
		return $this->hasMany(SensorGroup::class);
	}

	public function sensor_settings()
	{
		return $this->hasMany(SensorSetting::class);
	}
}

And Equipement Class

<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

class Equipement extends Model
{
	protected $table = 'equipement';
	public $timestamps = false;

	protected $casts = [
		'equipement_id' => 'int',
		'latitude' => 'float',
		'longitude' => 'float',
	];

	protected $fillable = [
		'location_id',
		'name',

	];



	public function location()
	{
		return $this->belongsTo(Location::class);
	}

	public function sensors()
	{
		return $this->hasMany(Sensor::class);
	}
}

Thank in advance !

Activity icon

Started a new Conversation Eloquent Multiple Relationship Return Attributes Array

I have three tables : sensors, equipement, location

In sensor Table, I have

	public function equipement()
	{
		return $this->belongsTo(Equipement::class);
	}

In Equipement table, I have

	public function location()
	{
		return $this->belongsTo(Location::class);
	}

What I would like to do is returning in one query all the informations regarding the sensor + the equipement association and the location associated to this equipement.

I did something like


    public function all()
    {
        $sensors = Sensor::with('equipement', 'equipement.location')->get();

        return $sensors;
    }

It seems to works. However, when I want to loop in Blade, the equipement and location are not objects but array.

@foreach ($sensors as $sensor)
             <tr>
            <td>{{ $sensor->id }}</td> //Working
            <td>{{ $sensor->device_number }}</td>  //Working
             <td>{{ $sensor->installation_date }}</td>  //Working
             <td>{{ $sensor->equipement->name}}</td> //This is not working. I need instead to do  $sensor->equipement['name']
<td>{{ $sensor->equipement->location->name}}</td> //This is not working.

</tr>

In Tinker, when I do $sensors = Sensor::with('equipement', 'equipement.location')->first();, I'm able to access as an object the attribute of the equipement and the location. I know, I'm getting the object with first() but with get(), as I loop, it should be the object as well no ?

Could you please help me ?

In Blade, I would like to access attributes as an object and not array. Thank you.