TutanRamon

TutanRamon

Member Since 3 Years Ago

Experience Points
2,850
Total
Experience

2,150 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
7
Lessons
Completed
Best Reply Awards
3
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
2,850 XP
May
26
6 days ago
Activity icon

Replied to BelongsToMany Between Pivot Model And Regular Model

Basicly: see Dossier as as Tag. A Article+Site combination (articleSite) can have zero or more tags.

Activity icon

Replied to BelongsToMany Between Pivot Model And Regular Model

@kkhicher1 That's because it's a many-2-many. I have a table article_site_dossier.

Activity icon

Started a new Conversation BelongsToMany Between Pivot Model And Regular Model

UPDATE: (changed title of topic. Updated title better describes the problem I am having).

I have 4 models (simplified version)

Article
  id
  title

Site
  id
  url
  name

Dossier
  id
  site_id
  name

ArticleSite  (extends pivot)
  id
  article_id
  site_id

I defined the following relations

Article      belongsToMany   Site      using    ArticleSite
Site         belongsToMany   Article   using    ArticleSite
Dossier      belongsToMany   ArticleSite
ArticleSite  belongsToMany   Dossier

The relation between Article and Site is working well. I am experiencing difficulties while saving one or more Dossier to ArticleSite.

I use the sync method to do this, but Laravel keeps returning this error: SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'field list' (SQL: insert into article_site_dossier (``, dossier_id) values (?, 5))

I tried defining the column fields in the belongsToMany function, but then the error is about a null value.

The use case of the setup is as follows:

There are multiple Article
There are multiple Site
There are multiple Dossier
One Site has zero or more Dossier
One Article can be shown on multiple Site
One Article (on a Site) can be put in zero or more Dossier

Can anybody tell me what I am doing wrong? Big thanks in advance.

May
21
1 week ago
Activity icon

Started a new Conversation Multi Site News System: Setup Complexity Problem

I am building a multi site news application. So, for instance: while creating a news item (article) I can select multiple sites where I want the item to be shown. Each site has his own "categories" and "dossiers".

Now, I have several models but I repeatedly questioning myself I this is the right approach.

Article Site Category Dossier (= file, not a physical file, but a file as in "part of larger collection of items around a certain subject". Kind of tag.)

An article is attached to 1 or more sites -> "ArticleSite" model

In my Article model I have this pivot relation defined:

public function sites()
{
	return $this->belongsToMany('App\Site')->withTimestamps()->using('App\ArticleSite');
}

The same for my Site model:

public function articles()
{
	return $this->hasMany('App\Article')->withTimestamps()->using('App\ArticleSite');
}

I created a ArticleSite model for the relationship.

class ArticleSite extends Pivot
{
	protected $table = 'article_sites';

	public function dossiers()
	{
		return $this->belongsToMany('App\Dossier', 'article_site_dossiers', 'articlesite_id', 'dossier_id');
	}
}

As you can see, I created a method "dossiers" on the ArticleSite model because a "dossier" is related to article+site. On site A it can be attached to dossier "X" while the same article on site B it can be attached to dossier "Y". Hence, this setup. I am also planning to do this for the categories. Each site holds different categories.

Now, I am having trouble with the dossiers() method. When saving a new article, I can the exception: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'articlesite_id' cannot be null (SQL: insert into article_site_dossiers (articlesite_id, dossier_id) values (?, 1), (?, 5))

This is the part of the ArticleController save method

$articleSite->save();
		
if (isset($request->input('dossiers')[$articleSiteId]))
{
	$articleSite->dossiers()->attach($request->input('dossiers')[$articleSiteId]);
}

(On the frontend I render multiple form sections for each selected site. That's why I use the brackets notation.)

I save the ArticleSite model, so there must be an Id available. I don't get it...

Am I trying to achieve the right setup, or am I trying to get something to work that shouldn't work in the first place? Are there other ways to achieve what I want?

May
20
1 week ago
Activity icon

Replied to How To Search For An Item With Relationships (SOLVED)

Take a look on a recent topic on a similar question. https://laracasts.com/discuss/channels/eloquent/query-with-attributes-from-related-model

@MichalOravec 's answer will give you some clues about how to handle this.

Activity icon

Replied to How To Search For An Item With Relationships (SOLVED)

Can you post your models?

Apr
30
1 month ago
Activity icon

Replied to How To Delete File In Local

But, where is the file located? What is the path on the file on your disc? And how did it came up there?

Apr
29
1 month ago
Activity icon

Awarded Best Reply on Database Relationship

Your users table is missing a foreign key to the profiles table.

Add this to the users table:

$table->bigInteger('profile_id')->unsigned()->nullable();
$table->foreign('profile_id')->references('id')->on('profiles');

EDIT: I think MichalOravec's approach is even better in this case.

Activity icon

Awarded Best Reply on Using Foreach With Old Helper In Laravel Blade

Can you try this:

 @foreach (old('invoices_items') as $i => $invoice_item)
  <input class="input" type="text" name="invoice_items[{{ $i }}][description]" value="{{ $invoice_item[description] }}">
  <input class="input" type="text" name="invoice_items[{{ $i }}][amount]" value="{{ $invoice_item[amount] }}">
  @endforeach

Also, you can skip the @if-check and provide the old helper with an additional empty array:

@php $defaultValues = array(array('description' => '', 'amount' => ''));
@foreach (old('invoices_items', $defaultValues) as $invoice_item)

With the approach, your code will be cleaner.

(not tested it myself, but you get the point)

Activity icon

Replied to Database Relationship

Your users table is missing a foreign key to the profiles table.

Add this to the users table:

$table->bigInteger('profile_id')->unsigned()->nullable();
$table->foreign('profile_id')->references('id')->on('profiles');

EDIT: I think MichalOravec's approach is even better in this case.

Activity icon

Replied to Problem With Populating Database Column With Seeding In Laravel

$user_interests_values is an array, so the exception is kind of valid because he expects a string.

How many interests are there in your interests table?

Because you can also do

'interested_in' =>  rand(1,10)    // generate random id, assuming there are 10 interests with id 1..10

This is a bit dirty, but a quick solution if you just need it for testing purposes.

Activity icon

Replied to Database Relationship

Yes, but show us your migration files for profile and user.

Activity icon

Replied to Database Relationship

If you take a look at the Laravel documentation, you can see the following example:

class User extends Model
{
    /**
     * Get the phone record associated with the user.
    */
    public function phone()
    {
        return $this->hasOne('App\Phone');
    }
}

See https://laravel.com/docs/7.x/eloquent-relationships

So, you are on the right track.

I prefer hasOne('App\Phone') instead of hasOne(Phone::class);

Activity icon

Replied to Using Foreach With Old Helper In Laravel Blade

Can you try this:

 @foreach (old('invoices_items') as $i => $invoice_item)
  <input class="input" type="text" name="invoice_items[{{ $i }}][description]" value="{{ $invoice_item[description] }}">
  <input class="input" type="text" name="invoice_items[{{ $i }}][amount]" value="{{ $invoice_item[amount] }}">
  @endforeach

Also, you can skip the @if-check and provide the old helper with an additional empty array:

@php $defaultValues = array(array('description' => '', 'amount' => ''));
@foreach (old('invoices_items', $defaultValues) as $invoice_item)

With the approach, your code will be cleaner.

(not tested it myself, but you get the point)

Activity icon

Replied to How To Delete File In Local

Well, basically you are now saying Hey Laravel, please delete http://localhost/atc/public/images/workerprofile/Crystalsproof_ofpraveen.png

That's not going to happen. You need to have a reference to the actual file.

use Illuminate\Support\Facades\Storage;

Storage::delete('file.jpg');

See https://laravel.com/docs/7.x/filesystem#deleting-files

Apr
28
1 month ago
Activity icon

Replied to @error Shows Nothing While There Is An Error

Hi Tray2,

Makes no difference. The validation error is shown, but when I switch to @error directive, nothing happens. (I am using to apply corresponding css classes bootstrap.)

Activity icon

Started a new Conversation @error Shows Nothing While There Is An Error

Ok, I have something really weird going on.

I am running the latest Laravel 7 release. Basically, I have a simple controller which validates some user form input.

public function store(Request $request)
{
  $this->validate($request, [
    	'title' => 'required|min:10|max:255',
  ]);

  //rest of the logic
}

When I submit my form (with an incorrect title), the validation trait handles this well. However, my blade file isn't showing the error.

I tried this

@if ($message = Session::get('error'))
  <div class="alert alert-danger alert-dismissable m-t-md">
  {{ $message }}
  </div>
@endif

Nothing shows up. I also tried the @error directive. Nothing happening either.

@error('title')
   <div class="alert alert-danger alert-dismissable m-t-md">
      {{ $message }}
    </div>
@enderror

First I thought the session wasn't flashed correctly. But when I do this:

dd(session()->all()); //in the create method

I got this response:

...
"errors" => Illuminate\Support\ViewErrorBag {#312
#bags: array:1 [
  "default" => Illuminate\Support\MessageBag {#313 
    #messages: array:1 [
      "title" => array:1 [
        0 => "The title must be at least 10 characters."
      ]
    ]
    #format: ":message"
  }
]
}
...

However, when I changed the Blade file to this, it works:

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

Does anybody have an idea why @error isn't working?

Activity icon

Replied to I Need To Understand Route And URL

Otherwise, please try a slash before books

Route::resource('/books', 'BooksController')
Activity icon

Replied to Json Url Pass To Laravel Api

I don't understand what you are trying to explain here. Can you explain it with some more information or code?

Activity icon

Replied to Load Default Values From Database To Model

I think you should fix this within the constructor method in your model class.

public function __construct()
{
    $this->something = "default value"; //or fetch from db.
}

One downside I can think of: for every new model, at least one extra db query is fired (to fetch the default values).

Or, if it involves almost all of your models, you should write some generic code that handles this.

Activity icon

Awarded Best Reply on Retain Value Of Radio Button, But Set Default Value

I think you should change

{{ (old('available') == 'unknown') ? 'checked' : ''}}

to

{{ (old('available', 'unknown') == 'unknown') ? 'checked' : ''}}

Now, you pass a default value for "available" if the old value is not set.

Activity icon

Replied to Retain Value Of Radio Button, But Set Default Value

I think you should change

{{ (old('available') == 'unknown') ? 'checked' : ''}}

to

{{ (old('available', 'unknown') == 'unknown') ? 'checked' : ''}}

Now, you pass a default value for "available" if the old value is not set.