zerodps

zerodps

Member Since 2 Months Ago

Experience Points 7,060
Experience Level 2

2,940 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 62
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.

21 Aug
20 hours ago

zerodps left a reply on Undefined Variable: $loop In @foreach

hey guys,

Thanks guys, I seem to have missed the part about the blade view....

I'm trying to update my existing project, which contains 3 images, all stored in a table, but in a single row. So I thought I'd update my image table with a foreach loop (my knowledge is very limited at this moment and is a learning project :))). Im stuck at :

$image[$loop->index]->save();


As @alkut mentioned: " $img variable is the index now. and explain what you trying to do."

$image[$img->index]->save();

What does this mean can i just use it like $loop ?

$image->save();

This would result in an error because $image is an collection of all three images containing in the project.

I tried to achieve something like an dynamic variable which will increment after the loop has finished.

So it would result in something like this

/* first */
$image[0]->save();
/* second */
$image[1]->save();
/* third */
$image[2]->save();

Thanks again for your time and input !

zerodps started a new conversation Undefined Variable: $loop In @foreach

Hi guys,

i am trying to iterate some data in my controller like this :

if(request()->hasFile('image')); {
            foreach(request()->file('image') as $img) {
                $image = Image::where("images.project_id", "=", $project->id)
                ->get();
    /* some code */
        
        $image[$loop->index]->save(); 

I keep getting the error

ErrorException (E_NOTICE)
Undefined variable: loop

I could not find any resource in the documentation therefor i ask you guys again :)

Thanks in advance !

20 Aug
1 day ago

zerodps left a reply on SQL Query With Variable / Laravel 5.6 MacOS

Hey @nakov,

thank you very much for your insight, as i mentioned the ORM topic is not my strongest topic :) I really need to take a closer look at the documentation !

zerodps started a new conversation SQL Query With Variable / Laravel 5.6 MacOS

Hi all,

Im trying to amend my SQL Query which is working fine to use an variable (or a helper function).

$aa = DB::select('select projects.*, users.*, thumbnails.* from thumbnails inner join projects, users where projects.id = thumbnails.id && users.id_user = projects.user_id');

I would like to use this instead of users.id_user = projects.user_id

$this_user = auth::user()->id_user;

users.id_user = $this_user

Im not really comfortable using Eloquent it is one of my working progresses :)

Thanks for your help !

zerodps left a reply on Trouble With Authentication / Laravel 5.6 MacOS

@nakov @tykus Hey guys, thank you very much for your input. your suggestions worked like a charm

zerodps started a new conversation Trouble With Authentication / Laravel 5.6 MacOS

Hi all,

i recently updated my users table primary key (ID),

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id_user');
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

After adding this to my user model everything is working fine

  protected $primaryKey = 'id_user';

The only error im seeing is that the built in laravel authentication is not working properly

$projects = auth::user()->project; 
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'projects.user_id_user' in 'where clause' (SQL: select * from `projects` where `projects`.`user_id_user` = 1 and `projects`.`user_id_user` is not null)

Im quite helpless at this point because im not quite sure how to update the authentication to anticipate my changes. In addition to that I dont really know why SQL is calling 'projects.user_id_user'.

Any help is greatly appreciated. If im missing any information im happy to share.

Thanks

10 Jul
1 month ago

zerodps left a reply on MergeRecursive() In The Documentation

Thanks for the insight !

zerodps started a new conversation MergeRecursive() In The Documentation

hi all,

i was wondering if this is a typo. merge recursively also uses the merge() method. I also couldn't find a mergeRecursive() method in Illuminate/Support/Collection.php. So what is the difference between merge and mergeRecursive() ?

mergeRecursive()

The mergeRecursive method merges the given array or collection recursively with the original collection. If a string key in the given items matches a string key in the original collection, then the values for these keys are merged together into an array, and this is done recursively:

$collection = collect(['product_id' => 1, 'price' => 100]);

$merged = $collection->merge(['product_id' => 2, 'price' => 200, 'discount' => false]);

$merged->all();

// ['product_id' => [1, 2], 'price' => [100, 200], 'discount' => false]

zerodps left a reply on Undefined Offset: 0 / WAMP W10 L5.8.27

fyi

my controller looks like this

        $aa = DB::select('select projects.*, users.*, images.filename, images.project_id from images inner join projects, users where projects.id = images.project_id && users.id = projects.user_id');

my view:

@foreach ($aa as $a)
<div class="content">
    <div class="content-container">
            <img src="{{'storage/' . (($a->filename)) }}"
08 Jul
1 month ago

zerodps left a reply on Undefined Offset: 0 / WAMP W10 L5.8.27

Hey @mstrauss ,

Thanks for your input !

"Also, does each $project have an image stored at $project['image'][0]->filename?"

Yes and in the future there should be no limit on images within a project. I am reading "https://laravel.com/docs/5.7/eloquent-mutators" at the moment to figure out how i could access the image array dynamicly...

Yeah as @sergiu17 pointed out the error lies in the "[0]". That is why i figured i should call the image array with something like [$id]

zerodps left a reply on Undefined Offset: 0 / WAMP W10 L5.8.27

Hi Sergiu17,

yeah thats exactly the point i guess. Would you mind show me how to use a "wildcard" when calling in an array ?

zerodps left a reply on Undefined Offset: 0 / WAMP W10 L5.8.27

So I just saw that i get the error message when using var_dump

var_dump($project['image'][0]->filename)

Could someone explain why dd() would not show this error ?

zerodps started a new conversation Undefined Offset: 0 / WAMP W10 L5.8.27

Hi all,

im facing a wierd undefinded offset problem.

My Controller

 public function index(Project $project, User $user,Image $image)
    {
        $projects = Project::all();

                
        return view('projects.test', compact('projects'));
    }

my loop

@foreach ($projects as $ $project)
                            <div class="content-container"><img src="{{storage_path() . "\app\public\" . ($project['image'][0]->filename)}}"

the dd is outputting the correct file

@foreach ($projects as $project)
 <?php dd($project['image'][0]->filename) ?>

Trying to view it in the browser will result in the undefined offset error.

Any help is greatly appreciated. BTW if someone could send me any advanced resource about eloquent, i would be super hyped, since it seems the documentation just so covers the basics

05 Jul
1 month ago

zerodps left a reply on Expected Data Type For GetClientOriginalExtension() / L 5.8.27 WAMP W10

For anyone with the same struggle, this is my solution which is working at the moment :)

public function store(Project $project, User $user,Request $request)
    {
        $attributes = $this->validateProject();
        $attributes['user_id'] = auth()->id();
        
        $img = request()->file('image');
        $this->validateImage();      
        $extension = $img->getClientOriginalExtension();
        Storage::disk('public')->put($img->getFilename().'.'.$extension, File::get($img));
        
        $image = new Image();
        $image->mime = $img->getClientMimeType();
        $image->original_filename = $img->getClientOriginalName();
        $image->filename = $img->getFilename().'.'.$extension;
        $image->project_id = auth()->id();
        $image->save();

        Project::create($attributes);

        return redirect('/projects');
  
    }

zerodps left a reply on Expected Data Type For GetClientOriginalExtension() / L 5.8.27 WAMP W10

Hey msstrauss,

i have allready tried this. With this approach im back to:

Call to a member function getClientOriginalExtension() on array

zerodps left a reply on Expected Data Type For GetClientOriginalExtension() / L 5.8.27 WAMP W10

So I tried some different ways but i am unable to find my mistake.

As Snapey mentioned "but when you upload a file, the request contains an instance of the uploaded file object. Only on this object can you call methods like getClientOriginalExtension()"

I have tried to call getClientOriginalExtension with the explicit request but this will end in the error "Call to a member function getClientOriginalExtension() on string" again

Am i missing something here ?

zerodps left a reply on Expected Data Type For GetClientOriginalExtension() / L 5.8.27 WAMP W10

Hi Snapey,

thanks for your insight. It allready helped me alot !

is this information sufficient ?

     protected function validateImage()
     {
        return request()->validate([
            'image' => ['required']
    ]);    
     }

zerodps started a new conversation Expected Data Type For GetClientOriginalExtension() / L 5.8.27 WAMP W10

hi all,

sorry for the stupid question, but I couldn't find any information in the documentation.

so this is my code snippet

  $img = $this->validateImage();
        $img['project_id'] = auth()->id();
        $extension = $img->getClientOriginalExtension();
        Storage::disk('public')->put($img->getFilename().'.'.$extension, File::get($img));

This will give me the error

Call to a member function getClientOriginalExtension() on array

My solution was

$extension = $img['image']->getClientOriginalExtension();

Which will give me the error

Call to a member function getClientOriginalExtension() on string

How can i resolve this ?

zerodps left a reply on Relationship Between Two Loops / Laravel 5.8.26 WAMP W10

Hey, yes sorry didnt thought about this. Unfortunately i didnt found any solution i just changed my approach .. quite new to this site ..

zerodps started a new conversation Storing Values In Different Tables From A Single Controller Function ? WAMP SQL L5.8.27

Hi all,

I am in the process of brainstorming for my upcoming project... My ideal process would be for the user to submit a single form with some text and an image, in the next step my [email protected] would store the text in a project table and my image references in an image table.

Currently I ignore images, so this is my [email protected], it works fine and my previous approach was to process the image in an additional controller, but I estimated that I wouldn't be able to submit the data in just one form......

$attributes = $this->validateProject();
        $attributes['user_id'] = auth()->id();

        Project::create($attributes);

        return redirect('/projects');

Is this even possible ? Am i overthinking the process ?

Any approach or resource for further education is greatly appreciated !

Thanks in advance,

zero

zerodps left a reply on How To Rollback Laravel/framework 5.8.27 /WAMP W10

Thanks guys, really appreciate it !

04 Jul
1 month ago

zerodps started a new conversation How To Rollback Laravel/framework 5.8.27 /WAMP W10

Hi all,

can i rollback a laravel framework update ? If yes, how ?

thanks in advancce

03 Jul
1 month ago
27 Jun
1 month ago

zerodps left a reply on Test Troubleshooting / WAMP Laravel 5.8.26 W10

@JAYTEE - Oh .. wow thanks for the quick answer and fix.

I really appreciate it!

zerodps started a new conversation Test Troubleshooting / WAMP Laravel 5.8.26 W10

Hi all,

I am trying to get this test running but phpunit is giving me a error message which leaves me more clueless than before...


Tests\Feature\ManageProjectsTest::a_user_can_create_a_project
Error: Class 'Tests\Feature\Project' not found


the test:


public function a_user_can_create_a_project()
    {
        $this->withoutExceptionHandling();
        $this->signIn();
        $this->get('/projects/create')->assertStatus(200);

        $attributes = [
            'title' => $this->faker->sentence,
            'description' => $this->faker->paragraph   
        ];

        $response = $this->post('/projects', $attributes);
        $response->assertRedirect(Project::where($attributes)->first()->path());

        $this->assertDatabaseHas('projects', $attributes);
        
        $this->get('/projects')->assertSee($attributes['title']);

I am certain that this line is the issue. However I cant explain the reason or any fix for it


     $response->assertRedirect(Project::where($attributes)->first()->path());


Thanks in advance !

25 Jun
1 month ago

zerodps left a reply on @foreach Loop Not Working? Laravel 5.8.24 (WAMP) W10

Hey guys,

it's finally working, thank you all so much. I really appreciate it. @snapey @wyatt44 @cronix @fabricecw

much love

zerodps left a reply on @foreach Loop Not Working? Laravel 5.8.24 (WAMP) W10

@SNAPEY - so given those two tables :

replies table:


     Schema::create('replies', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('thread_id');
            $table->integer('user_id');
            $table->text('body');
            $table->timestamps();
        });

threads table


Schema::create('threads', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id');
            $table->string('title');
            $table->text('body');
            $table->timestamps();
        });
    }

Should i change thread_id to bigIncrements or should i change the id to be an intenger ?

Sorry for late reply just came home from work ..

zerodps left a reply on @foreach Loop Not Working? Laravel 5.8.24 (WAMP) W10

@CRONIX - hi Cronix,

thanks to you aswell :)

my routes look like that :


Auth::routes();

Route::get('/home', '[email protected]')->name('home');
Route::get('/threads', '[email protected]');
Route::get('/threads/{thread}', '[email protected]');



zerodps left a reply on @foreach Loop Not Working? Laravel 5.8.24 (WAMP) W10

@SNAPEY - hi snapey,

thanks for your input !

 public function up()
    {
        Schema::create('replies', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('thread_id');
            $table->integer('user_id');
            $table->text('body');
            $table->timestamps();
        });
    }

I just saw that a few threads have the same thread_id but i cant migrate with thread_id set to bigIncrements

What should be the defintion for thread_id ?

zerodps left a reply on @foreach Loop Not Working? Laravel 5.8.24 (WAMP) W10

Hi,

thanks for your input. I really appreciate it. It seems like its empty ...

´´´

Collection {#230 ▼ #items: [] }

´´´

zerodps started a new conversation @foreach Loop Not Working? Laravel 5.8.24 (WAMP) W10

Hello everybody, I'm working on the series "Let's build a forum with Laravel." In episode 3, Jeffrey displays the thread-related answers with a foreach loop. The problem I have is that the browser does not display HTML elements after my foreach loop. When I comment out the loop and its code, the HTML elements are displayed in the browser.

My threads model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Thread extends Model
{
    public function path()
    {
        return '/threads/' . $this->id;
    }
    
    public function replies()
    {
        return $this->hasMany(Reply::class);
    }
}

My ThreadsController

    public function show(Thread $thread)
    {
        return view('threads.show', compact('thread'));
    }

my show.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{$thread->title}}</div>
                <div class="card-body">
                    {{ $thread->body }}                     
                </div>
            </div>
        </div>
    </div>
    <div class="row justify-content-center">
            @foreach ($thread->replies as $reply)
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">{{ $reply->created_at }}</div>
                    <div class="card-body">
                             
                                     <h4>
                                        {{ $reply->created_at }}   
                                    </h4> 
                                    <div class="body"> {{ $reply->body }} </div>
                           
                    </div>
                </div>
            </div>
            @endforeach
        </div>
</div>   


@endsection


After several hours of trying different approaches, I now hope for your support.

Thanks in advance