Greeenone

Greeenone

Member Since 7 Months Ago

Experience Points
200
Total
Experience

4,800 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
0
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.

Level 1
200 XP
May
30
4 months ago
Activity icon

Replied to VueJS Doesn't Display Data From Database - Any Errors

Solved! My vue script was in wrong place

Activity icon

Started a new conversation VueJS Doesn't Display Data From Database - Any Errors

Hello,

I'm learning Vue.JS for laravel and.. I have my first issue :( I'm watching watching course about CRUD using vue.js. I did exactly as in the course but my code doesn't work correctly.

My component display correctly the HTML code but not data from database.

TasksController.php

... public function index() { // $tasks = Auth::user()->tasks; return response()->json([ 'tasks'=>$tasks ], 200); } ...

Works perfectly. Display data from DB

app.js

... Vue.component('task-component', require('./components/TaskComponent.vue').default); ...

Also works perfectly

TaskComponent.vue

...

<button type="button" name="button">Add task</button>

<table class="table" v-if="tasks">
  <thead>
    <th>Name</th>
    <th>Content</th>
    <th>Edit</th>
  </thead>
  <tbody>
    <tr v-for="(task, index) in tasks">
      <td>{{index + 1}}</td>
      <td>{{task.name}}</td>
      <td>{{task.body}}</td>
      <td><button type="button" name="button">Edit</button>
        <button type="button" name="button">Deletes</button></td>
      </tr>
    </tbody>
  </table>
</div>

export default {
  data(){
    
    return {
      
      task:{
        name: '',
        body: ''
      },
      
      tasks: [],
      uri: 'http://127.0.0.1:8000/tasks'
      
    }
    
  },
  
  methods:{
    
    loadTasks(){
      axios.get(this.uri).then(response=>{
        
        this.tasks = response.data.tasks
        
      });
    }
    
  },
  
  mounted() {
    
    this.loadTasks();
    console.log('test');
  }
}

....

Feb
21
7 months ago
Activity icon

Replied to One To Many - First Results And Foreach For Subobjects

Yes !

Models:

ManagementFiles.php

class ManagementFiles extends Model { public function folders(){ return $this->BelongsTo('App\ManagementFolders'); } }

ManagementFolders.php

class ManagementFolders extends Model { public function files(){ return $this->hasMany('App\ManagementFiles', 'folder_id'); } }

====================================================================

Migration:

management_files

ID - PK AI file_name folder_id

management_folder ID - PK AI reference folder_name

=======================================================================

In controller I tried everything posted here

Activity icon

Replied to One To Many - First Results And Foreach For Subobjects

Still invalid argument :'( I think I will leave and use a simple query

$files = ManagementFiles::where('folder_id", $id)->get();

It's correct or it's better to use this frustrating oneToMany ?

Activity icon

Replied to One To Many - First Results And Foreach For Subobjects

I have this error now:

Invalid argument supplied for foreach()

I added second file and when I use dd, I see it.

#relations: array:1 [▼ "files" => Collection {#244 ▼ #items: array:2 [▼ 0 => ManagementFiles {#247 ▼ #connection: "mysql" #table: "management_files" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:9 [▶] #original: array:9 [▶] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] #guarded: array:1 [▶] } 1 => ManagementFiles {#248 ▶} ] } ]

Activity icon

Replied to One To Many - First Results And Foreach For Subobjects

ManagementFolders {#239 ▼ #connection: "mysql" #table: "management_Folders" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:21 [▶] #original: array:21 [▶] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: array:1 [▼ "Files" => Collection {#249 ▼ #items: array:1 [▼ 0 => ManagementFiles {#246 ▼ #connection: "mysql" #table: "management_Files" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:9 [▶] #original: array:9 [▶] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] #guarded: array:1 [▶] } ] } ] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] #guarded: array:1 [▼ 0 => "*" ] }

Activity icon

Replied to One To Many - First Results And Foreach For Subobjects

@RONB1985 - It's work. Thanks you ! :)

Oh still don't work.. When I add "with", return give me information about folder and files inside but loop still doesn't work :/

Activity icon

Replied to One To Many - First Results And Foreach For Subobjects

@SAURABHD - Works but I get the name of this folder. I want to display all files belongs to this folder.

Activity icon

Replied to One To Many - First Results And Foreach For Subobjects

Still not working. When I use Get, everwing works great.

Activity icon

Replied to One To Many - First Results And Foreach For Subobjects

@saurabhd Thanks for your help!

I have this error now:

Trying to get property 'name' of non-object

@RonB1985

ManagementFolders {#238 ▼ #connection: "mysql" #table: "management_folders" #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: false #attributes: array:21 [▶] #original: array:21 [▶] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #hidden: [] #visible: [] #fillable: [] #guarded: array:1 [▶] }

Activity icon

Replied to One To Many - First Results And Foreach For Subobjects

Thanks for reply !

Sure !

public function index($reference){

$folders = Folders::where('reference', $reference)->first();
//
foreach($folders->files as $file){
  echo $file->name;
}

}

//Folder model

public function files() { return $this->hasMany('App\Folders'); }

//File model

public function folders() { return $this->BelongsTo('App\Files'); }

And my Error

Invalid argument supplied for foreach()

Activity icon

Started a new conversation One To Many - First Results And Foreach For Subobjects

Hello !

I'm learning laravel since 2 weeks and I have some issues with my HasMany relation.

I have one folder and multiple files. Files belongs to one folder and on folder has many files.

I want to display all files inside in folder.

I get the ID from url and I "send" it to query

$folder = ManagementFolders::where('reference', $reference)->first();

After that, I want to display all files inside but my foreach doesn't work.

Property [file] does not exist on this collection instance.