Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

getupkid

Experience

7,400

6 Best Reply Awards

  • Member Since 9 Months Ago
  • 36 Lessons Completed
  • 0 Favorites

21st November, 2017

getupkid left a reply on Adding Data To A Model In A Query Scope • 3 weeks ago

It sounds like you are looking to add an Accessor:

https://laravel.com/docs/5.5/eloquent-mutators#accessors-and-mutators

9th November, 2017

getupkid left a reply on How To Get Information From Using All()->random(1) • 1 month ago

Perhaps it is because the 1 is there, but this works for me:

  $user = App\User::all()->random();
  echo $user->id;

getupkid left a reply on Laravel - Integrity Contraint Violation: 1062 Duplicate Entry. • 1 month ago

The problem is likely that faker is generating the same title twice and then it errors because the database is expecting something unique.

When you get the error can you verify whether or not the slug is already being used?

If that is the case, you will have to wrap your code in a try/catch or while loop that checks whether the title/slug already exists.

8th November, 2017

getupkid left a reply on "Failed To Parse Address" On Redis Connection - Laravel + Predis + Laradock • 1 month ago

@Talinon I figured it out... Docker was created in an environment variable REDIS_PORT that was being set to "tcp://172.17.0.5:6379". Not sure why, but anyways...

Changing my config/database.php to:

 'default' => [
             'host' => env('REDIS_HOST', 'redis'),
             'password' => env('REDIS_PASSWORD', null),
             'port' => 6379,
             'database' => 0,
         ],

solved the problem!

You definitely got me on the right track so thank you =)

getupkid left a reply on "Failed To Parse Address" On Redis Connection - Laravel + Predis + Laradock • 1 month ago

@Talinon I did try that, it gives the same error just with the address in it instead.

I believe it has something to do with the docker networking setup I'm using. I just tried it with the default laradock config and it was working fine.

It's just odd cause I have no issues with MySQL or anything else using the same setup. I'll see what I can figure out.

Thanks for your help anyway!

getupkid left a reply on "Failed To Parse Address" On Redis Connection - Laravel + Predis + Laradock • 1 month ago

@Talinon nope I don't have any Redis stuff in the .env - it's all done through the config files.

getupkid left a reply on Where To Place Reusable Queries • 1 month ago

They should be placed in the Model. See this for further reading:

https://laravel.com/docs/5.5/eloquent#query-scopes

getupkid started a new conversation Laravel + Predis + Laradock • 1 month ago

Hi everyone, I'm trying to setup Redis with a fresh laravel application. I set it as the driver for both caching and sessions.

However, I am getting this exception thrown:

 Predis \ Connection \ ConnectionException
 Failed to parse address "redis:tcp://172.17.0.13:6379" [tcp://redis:tcp://172.17.0.13:6379]

It sounds like something to do with the way the address is written but can't figure it out.

Here are some relevant details:

config/database.php 'redis' => [

         'client' => 'predis',

         'cluster' => false,

              'default' => [
                  'host' => env('REDIS_HOST', 'redis'),
             'password' => env('REDIS_PASSWORD', null),
             'port' => env('REDIS_PORT', 6379),
             'database' => 0,
         ],

     ]

config/session.php 'driver' => env('SESSION_DRIVER', 'redis'), 'connection' => 'default',

config/cache.php 'default' => env('CACHE_DRIVER', 'redis'),

 'stores' => [

         'redis' => [
             'driver' => 'redis',
             'connection' => 'default',
         ],

     ],

docker-compose.yml redis: build: ./laradock/redis volumes: - ./storage/data/redis:/data expose: - "6379" network_mode: bridge

17th August, 2017

getupkid left a reply on Npm Run Dev Error - Fresh Install • 3 months ago

OK thanks, I'll look into it.. but again, I'm using Laravel Homestead (which is up-to-date)... so I find it kind of odd that the correct version isn't applied.

getupkid started a new conversation Npm Run Dev Error - Fresh Install • 3 months ago

Hi everyone,

I'm running a completely fresh install of laravel 5.4.33, have changed no configs or anything (everything default), and the only commands I ran are "npm install" and then "npm run dev". I am getting the following error:

> @ dev /home/vagrant/Projects/FSXcms

npm run development

@ development /home/vagrant/Projects/FSXcms cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js

/home/vagrant/Projects/FSXcms/node_modules/laravel-mix/setup/webpack.config.js:24 let WebpackConfig = require('../src/builder/WebpackConfig'); ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:387:25) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32) at Function.Module._load (module.js:314:12) at Module.require (module.js:367:17) at require (internal/module.js:16:19) at requireConfig (/home/vagrant/Projects/FSXcms/node_modules/webpack/bin/convert-argv.js:97:18) at /home/vagrant/Projects/FSXcms/node_modules/webpack/bin/convert-argv.js:104:17 at Array.forEach (native)

npm ERR! Linux 3.19.0-25-generic npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "development" npm ERR! node v5.7.0 npm ERR! npm v3.6.0 npm ERR! code ELIFECYCLE npm ERR! @ development: cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @ development script 'cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request: npm ERR! /home/vagrant/Projects/FSXcms/npm-debug.log

npm ERR! Linux 3.19.0-25-generic npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "dev" npm ERR! node v5.7.0 npm ERR! npm v3.6.0 npm ERR! code ELIFECYCLE npm ERR! @ dev: npm run development npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @ dev script 'npm run development'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! npm run development npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request: npm ERR! /home/vagrant/Projects/FSXcms/npm-debug.log

29th May, 2017

getupkid left a reply on Unique Validation That Covers Three Tables • 6 months ago

Can you clarify your question?

Are you asking for the validation rule that checks to make sure that each "Reseller Address" is unique to an "Organization"?

5th April, 2017

getupkid left a reply on Is This Possible: HasManyThrough Through HasManyThrough? • 8 months ago

For anyone with this issue, this is the solution I came up with:

 $assignments = new Collection();

 foreach ($city->students as $student) {
      foreach ($student->assignments as $assignment) {
           $assignments->add($assignment);
      }
  }

Not sure if there is a cleaner way but I don't think the relationship can be defined properly this way. This at least got me the collection I was looking for.

getupkid left a reply on Can't Get Folders In Views To Work • 8 months ago

Once again had, creating the file views/pages/about.blade.php does not automatically create the route http://localhost:8000/pages/about

You have to specify a route for /pages/about in routes/web.php

4th April, 2017

getupkid left a reply on Laravel ManytoMany Problem Base Table Or View Not Found: 1146 • 8 months ago

Eloquent is expecting a pivot table called "category_gallery_image" and not "category_image". You only defined the change on one of the models.

CategoryGallery:

public function images() { return $this->belongsToMany(Image::class, 'category_image'); }

getupkid left a reply on Laravel ManytoMany Problem Base Table Or View Not Found: 1146 • 8 months ago

In a many-to-many relationship you need a pivot table, which you have not created.

Read more about many-to-many relationships which mentions which tables are needed and how they are set up.

getupkid left a reply on Elimination Of Repeated Code • 8 months ago

I would recommend not doing this at all. You should use authorization methods to check if the user owns the "Basics" they are trying to edit, and if not it will just throw a 401 error.

Read more about Laravel Authorization.

But if you insist, the above answer is OK.

getupkid left a reply on Eloquent Model Relationship With Itself • 8 months ago

You'll probably have to rethink this relationship.

You should probably add a middle man model in between this, for example called "Groups" or "Registrants" (or whatever you'd like to call it) and the relationship could be:

An Event has many Groups A group has many Participants

getupkid started a new conversation Is This Possible: HasManyThrough Through HasManyThrough? • 8 months ago

Is it possible?

Consider this hypothetical relationship, for example:

A city has many schools A school has many teachers A teacher has many students A student has many assignments

With hasManyThrough, I can get all the students from a city

 public function students() {
     return $this->hasManyThrough(Student::class, Teacher::class);
 }

but would it be possible to get all the assignments from a city?

I tried these two with no luck:

 // City model
 public function assignments() {
     return $this->hasManyThrough(Assignment::class, Student::class);
 }

(complains about there not being a foreign key for City on Students)

and:

 // City model
 public function assignments() {
     return $this->hasManyThrough(Assignment::class, $this->students());
 }

(fatal error)

3rd April, 2017

getupkid left a reply on Order By Eager Loaded Colum • 8 months ago

This is how I do it:

 $teachers = Teacher::join('accounts', 'teachers.id', '=', 'accounts.id')->orderBy('surname', 'DESC')->select('teachers.*');

then you can still access like such:

 foreach ($teachers->accounts as $account) {
      //
 }

I couldn't find a better way.

getupkid left a reply on Which Is The Placeholder For Different Request Rule? • 8 months ago

 'different'            => 'The :attribute and :other must be different.'

getupkid left a reply on Lookup Table For Four Models? • 8 months ago

Pivot tables are for many-to-many relationships. These sound like simple one-to-many relationships.

EX: "A text snippet belongs to a user"

It may be helpful to read the documentation about relationships and how they are defined. Always try to keep things as simple as possible, for example, consider if you need 5 different models or just one for "files" :)

getupkid left a reply on How To Retrieve Data From A Many-to-many Relationship Using Eloquent • 8 months ago

See documentation for many-to-many relationships

 foreach ($album->listeners as $listener) {
//

}

getupkid left a reply on VALIDATION: Ignore NULL Values For Unique • 8 months ago

Awesome Snapey, thank you. I completely missed that rule in the documentation.

getupkid left a reply on VALIDATION: Ignore NULL Values For Unique • 8 months ago

I tried that actually, but I think it's meant for when a value is not present at all. The value is technically present but it is just empty.

It's a form field that can be left blank.

getupkid left a reply on Hosting Advice • 8 months ago

Why do you need separate IP's for each application? You don't. Each one can be a virtual host pointing to a different directory.

getupkid started a new conversation VALIDATION: Ignore NULL Values For Unique • 8 months ago

Hello everyone,

Can you guys help me with a validation rule? I have it mostly working except I need it to allow NULL values which it doesn't seem to be doing.

Here is what I currently have:

 'orderNumber' => ['max:255', Rule::unique('transactions', 'order_number')->where(function ($query) {
                $query->whereNotNull('order_number')->where('merchant_id', auth()->user()->merchant->id)->where('status', 'C')->orWhere('status', 'S')->orWhere('status', 'P');
            })],

Validation is: order number must be unique to each merchant where status is C, S, or P, however it can be left blank (NULL)

24th March, 2017

getupkid left a reply on Why Scout Not Giving Result %LIKE%? • 8 months ago

TNTsearch is a full-text search and probably shouldn't be used for what you'e intending.

getupkid left a reply on How To Decouple Seeders And Model Factories • 8 months ago

If creating a factory for Post_Types is out of the question, then I don't see how you could get around this. There has to be some kind of defined Post_Type if a Post belongs to it.

getupkid left a reply on Toggle Config Values And Env Variables • 8 months ago

You can change env settings at any time in your application (for example: a in service provider or middleware) like so:

 config()->set($name, $value);

getupkid left a reply on Integrity Constraint Violation: 1062 • 8 months ago

It is trying to set a default value for all the rows that already exist in the database, and because you have not set a default or not allowed it to be nullable, it is setting affiliate_id as ''.

Since you specified that affiliate_id needs to be unique, it will complain that multiple rows are receiving the same default value of ''.

16th March, 2017

getupkid left a reply on Customize Laravel Login Throttling 5.4 • 8 months ago

That works! Thank you very much, you're the best :)

getupkid left a reply on Customize Laravel Login Throttling 5.4 • 8 months ago

Hi silverxjohn,

Thank you! I figured toying with the ThrottlesLogin trait was what was required, but could you provide a code block that modifies the lockout duration? (if possible, something that I can place in the LoginController so I'm not making copies of scripts, but if not that's ok)

It looks like it might be going another level deep to the RateLimiter class, but I'm a little unsure what's going on there and how to change it.

getupkid started a new conversation Customize Laravel Login Throttling 5.4 • 8 months ago

Is there a way to customize the max login attempts and how long the login is locked for on the LoginController? I tried maxLoginAttempts() and lockoutTime() methods from what I found online, but that was for 5.1 and doesn't seem to work.

I need to change it to: 6 failed attempts locks out the IP for 30 minutes.

Thanks in advance!

13th March, 2017

getupkid left a reply on Order By On Relationship Field • 8 months ago

I found the solution for anyone that needs the answer.

You have to use the join() method to sort the entire collection (instead of the eager loading I was trying which just orders the relationship.)

$order = 'desc';
$users = User::join('roles', 'users.role_id', '=', 'roles.id')->orderBy('roles.label', $order)->select('users.*')->paginate(10);

getupkid started a new conversation Order By On Relationship? • 8 months ago

How can I order a result set by something it's relationship.

I am trying to get the Eloquent equivalent of this:

SELECT * FROM users INNER JOIN roles ON users.role_id = roles.id ORDER BY roles.label

Here is what I'm trying (based on the documentation):

$order = 'desc';
$users = User::with(['role' => function ($q) use ($order) {
            $q->orderBy('label', $order);
        }])->paginate(10);

but it doesn't order them properly. What am I doing wrong?

6th March, 2017

getupkid left a reply on One-to-one Relationship On A Pivot Table? • 9 months ago

Cool thanks. I may be overcomplicating it but I couldn't think of a simpler design.

If it helps to add more context, basically an agent can make a 'commission' (which would be a good word to describe the 'something' you refer to) off any account, which is represented by a entry in the fee table.

I think that what you provided is the right solution. In essence, it would be creating a model that represents the pivot table ("Commission") and adding the One-to-One relationship to Fee in there, correct?

getupkid started a new conversation One-to-one Relationship On A Pivot Table? • 9 months ago

I can't think of how to handle this in Eloquent. I have a many-to-many relationship that needs a one-to-one relationship assigned to it.

Here is the basic database structure I designed in its simplest form:

ACCOUNTS: id AGENTS: id FEES: id ACCOUNT_AGENT: account_id, agent_id, fee_id

Each Account belongsToMany Agents - and each Agent belongsToMany Accounts. **Each "Account_Agent" (the many-to-many pivot table) belongsTo Fee.

How do I define that second relationship** in an Eloquent model?

Thanks, hopefully my question is clear.

Edit Your Profile
Update

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