Cruorzy

Experience

7,570

2 Best Reply Awards

  • Member Since 2 Weeks Ago
  • 62 Lessons Completed
  • 21 Favorites

20th July, 2018

Cruorzy left a reply on Upload File • 1 hour ago

What is the question exactly? and please a bit more info than 2 lines :)

19th July, 2018

Cruorzy left a reply on How To Convert Laravelcollective Form To Normal Form • 18 hours ago

Take 5-10 minutes of your time to just rewrite them

or

Go to the page press F12 and copy the source

Cruorzy left a reply on How Use Scenario In Validation Rules In Laravel • 18 hours ago

@techyad public static function getRules() is not a method provided by Laravel.

And indeed in the UpdateClass I called the public static function getRules() to import rules into the update rules() method.

You can either only make 1 class for creating and also use it for updating. But I mostly keep them seperated and just call the Create class and get the rules from that static method.

So when I need to add another field for updating, for example 'super_admin' I can easly add that in the Update class and not pull it in the Create class.

Cruorzy left a reply on How Use Scenario In Validation Rules In Laravel • 20 hours ago

No idea what scenario in yii2 is, only used Laravel so far.

A solution told to me was the following

I create a Update and Create Request by php artisan make:request.

Then I specify in the create the rules my validation should be but in a custom static class. and in the normal rules() function I call the self static method. and in the Update request i also call that static method.

class CustomerRequest()
{
  
    /**
     * @return array
     */
    public static function getRules(){
        return [
            'customer'=>'required'
        ]
    }
  
    /**
     * @return array
     */
    public function rules(){
        return self::getRules();
    }
}
class CustomerTaskRequest
{

    /**
     * @return array
     */
    public function rules(){
        return array_merge(
            [
                'task.name'=>'required',
            ],
            CustomerRequest::getRules()
        );
    }
    
}

18th July, 2018

Cruorzy left a reply on How To Solve Laravel NotFoundHttpException • 1 day ago

Please show us some code and which route you want to hit.

Cruorzy left a reply on Laravel 5 - How To Display Data From Database For A Specific User From Other Table • 1 day ago

//Task
 public function user()
    {
        return $this->belongsTo('User::class');
    }

//User
  public function task()
    {
        return $this->hasMany('Task::class');
    }

Those to need to be like that.

You could use Task::class or

return $this->hasMany('\App\Task');

Both work for making a relation

Cruorzy left a reply on Laravel 5 - How To Display Data From Database For A Specific User From Other Table • 1 day ago

Updated my reply, also show you code of the migrations / Model and View

Cruorzy left a reply on Laravel 5 - How To Display Data From Database For A Specific User From Other Table • 1 day ago

Task.php

public function user()
{
    return $this->belongsTo('App\User');
}

User.php

// User can have 1 task
public function task()
{
    return $this->hasOne('App\User');
}

/*
* User can have many tasks
public function tasks()
*{
 *   return $this->hasMany('App\User');
*}
*/

TaskController.php

// Returns the view with $task varibable
public function show(Task $task)
{
    return view('tasks.show', [
        "task" => $task
    ]);
}

tasks/show.blade.php

dd(Auth::user()->task);

/*
* If the user has many tasks
* dd(Auth::user()->tasks);
*/

// Test task relationship
dd($task->user);

17th July, 2018

Cruorzy left a reply on How To Make Dynamic Url In Laravel • 3 days ago

Not sure what the question is but getting data from the database to the view is instantly covered in a laracast lesson, make you sure watch some videos before you begin hacking.

Cruorzy left a reply on Custom Class Is Not Found On Nginx Server • 3 days ago

Could be a simple change of php versions, make sure you have atleast php 7.1.3 May be fixed when you put a \ before it.

16th July, 2018

Cruorzy left a reply on Importing Data From A CSV • 4 days ago

Lat time I did it I used a seeder, its fine probably but you lose the quick rebuild of a database when its a lot of data.

Normally when building up a project I seed like a million of times to test when adding something new, but since you live data is there it would be more of a mess. You can either use that data to test or add something that laravel knows when it has to seed that specific data or just use factory's

You can also probably make a custom artisan command for it and use it when needed.

13th July, 2018

Cruorzy left a reply on When I Migrate Files It Only Shows Varchar(191) Instead Of 255 • 1 week ago

When using MariaDB make sure you have the latest version 10.3 I know the newest debian installs 10.1 which has a error message shown up that the key is too long.

Cruorzy left a reply on Css Js File Not Loading • 1 week ago

Why copy? you should use NPM for this to compile them to 1 file. This is very useful specially since the npm run prod does minimize the file for a tiny speed boost.

dev = "npm run prod" prod = "npm run prod"

and include the new files in the app.scss

Cruorzy left a reply on Multiple Eloquent Relationship • 1 week ago

Since the Address table would be a poly table you have to do from the customer model also a MorphMany, reading up on this is very useful.

Haven't personally used MorphOne so you should check if that works, I can find people who used it so should be fine.

Also your migrations should be different that will be explained in the docs.

Cruorzy left a reply on Multiple Eloquent Relationship • 1 week ago

Following code is not fully functional but it seems like you want to make use of "Polymorphic Relations" read up on it since I can give you code but you should really need to understand it

https://laravel.com/docs/5.6/eloquent-relationships#polymorphic-relations

https://laracasts.com/series/how-do-i/episodes/8

class Customer extends Model
{
    public function contacts()
    {
        return $this->hasMany(\App\Contact::class);
    }
}

class Contact extends Model
{
    public function address()
    {
        return $this->morphOne('App\Address', 'address');
    }
}

class Job extends Model
{
    // Not sure if a job should have multiple addresses?
    public function addresses()
    {
        return $this->morphMany('App\Address', 'address');
    }
}


class Address extends Model
{

    public function commentable()
    {
            return $this->morphTo();
    }

}

12th July, 2018

Cruorzy left a reply on Page Not Found Error When Using Laravel • 1 week ago

Post some code please :)

Cruorzy left a reply on How Must Define Relationships Between Models? • 1 week ago

// user model class
class User extends Model {


    public function reviews()
    {
        return $this->belongsToMany('App\Group', 'user_groups');
    }

}

To directly return all posted reviews from by the users

11th July, 2018

Cruorzy left a reply on Redirecting Back On Validation Error Instead Of 422 JSON • 1 week ago

Can you post code snippets? not sure if there were huge changes since then.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.