0 Best Reply Awards

  • Member Since 1 Month Ago
  • 0 Lessons Completed
  • 0 Favorites

20th March, 2017

VortixDev started a new conversation How To Interlink Table Insertions • 1 month ago

When an entry is inserted in one table (let's call it "table 1"), I want an entry to be inserted into another table as well (let's call it "table 2") (I actually want to have data inserted into one of three potential tables depending on certain information, which is why it's not all under one table). From what I understand, the best way to do this is to create an observer to listen for the "creating/created" events and insert a row into "table 2" when that event occurs. I'm hoping there's an easy way to ensure that if the insertion I control for "table 2" fails, I can prevent the entry to "table 1" which is occuring under the "creating" event from being created as well. Is there an ideal way to do this?

19th March, 2017

VortixDev left a reply on How To Change Insertion Procedures Of A Model • 1 month ago

Looks perfect, thank you!

VortixDev started a new conversation How To Change Insertion Procedures Of A Model • 1 month ago

When one model inserts a new row into its table, I also want it to call upon another model to insert a new row into its table. Let me explain:

I have created three types of accounts, and each of these has a relationship with a central "BaseUser" model. This is necessary as certain information such as email address should be unique through all the accounts, so that a user of account type 1 cannot have the same email address as account type 2. This is made easier by the central "base table". Additionally is the reason of identifying the account type of the user, which is important for operations like password resets.

This means that when a user registers for account type 1, I also want the BaseUser model to create a new entry in its table. I have defined the relationship between this central model and all of the individual account type models, but I'm not sure if there is a simple way to define behavior for the insertion of data other than overriding save and firstOrCreate, and any other methods that may deal with the insertion of data.

26th February, 2017

VortixDev left a reply on Auth::guard('guard')->guest() - Trying To Get Property Of Non-object • 1 month ago

Also, removing the condition and using the following:

{{ gettype(Auth::guard('radius')) }} {{ gettype(Auth::guard('radius')->guest()) ? "True" : "False" }}

Gives me "object" and "True" as results.

VortixDev left a reply on Auth::guard('guard')->guest() - Trying To Get Property Of Non-object • 1 month ago

Unfortunately it seems that Auth::check() only checks for one guard, rather than for both my guard and the in-built web guard.

The following check exists within the layout file:

@if (Auth::guard('web')->guest() and Auth::guard('radius')->guest())

That produces an error when I visit the login page: "Trying to get property of non-object", even though {{ gettype(Auth::guard('radius')) }} and {{ gettype(Auth::guard('radius')->guest()) }} confirm that Auth::guard produces an object and the guest method can be applied to that to produce a boolean. Removing the Auth::guard('radius') check and leaving in the Auth::guard('web') check makes the issue go away.

When, however, I visit the home page, the error doesn't show, even with both conditions in. The main difference between the two pages is the middleware used - "auth" is used by the home controller, whereas "guest" is used by the login page. The home controller uses "auth:web,radius" so that it can redirect any users who aren't logged in with my custom guard as well as the in-built session guard. The login controller uses "guest" alone, redirecting anyone who is logged in using "web" away from the login pages. This means that my "radius" guard is not redirected away. I am wanting to modify the "guest" middleware to make it do so, and this would circumvent my problem, however I don't want to move on until I understand and fix the issue.

To test, I changed the login page to use the "auth" middleware with the parameters I specified for the home controller to use. When I did this, I could use both conditions previously stated without receiving the error.

VortixDev started a new conversation Auth::Guard - Trying To Get Property Of Non-object • 1 month ago

I use Auth::guard('guard')->guest() in the layout of my page to determine whether or not to show the "Login" and "Register" buttons or not - this 'guard' is the guard I have created for a second type of user my system uses. When I'm on a page which uses a controller that utilises the "auth" middleware with parameters "web,guard" then the page loads correctly, but when I visit a page which uses a controller that utilises the "guest" middleware with no parameters then the page doesn't load correctly and gives the error "Trying to get property of non-object". When I (on the same page) have the result of guest() and the result's type printed I get that it is a false boolean (as expected). When I print the type of Auth::guard('guard'), I get that it is an object. I'd appreciate any help understanding this.

Edit Your Profile

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