I have 3 DB tables and I did not put any relationship on any of them. then I wrote the following code:
public function store($key)
{
$user_key = md5(Input::get('email') . "-" . strtotime('now'));
$user = new User;
$user->name = Input::get('name');
$user->email = Input::get('email');
$user->user_key = $user_key;
$user->password = Hash::make(Input::get('password'));
$user->apipass = md5(Input::get('password'));
$user->save();
$newUid = $user->id;
//check key for share
$invited = DB::table('invites')->where('invite_key', Input::get('invite_key'))->where('status', '0')->count();
if($invited == 1) {
$inviter_id = DB::table('invites')->where('invite_key', Input::get('invite_key'))->where('status', '0')->pluck('user_id');
$read_only = DB::table('invites')->where('invite_key', Input::get('invite_key'))->where('status', '0')->pluck('read_only');
$share = new RecordShare;
$share->user_id = $inviter_id;
$share->shared_with_id = $newUid;
$share->read_only = $read_only;
$share->save;
}
return Redirect::to('login');
}
its supposed create a new user, then see who invited him, and then create a share record with the inviter.
but when I test it, I got the error:
LogicException
Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation
open: /home/oneinfin/public_html/dialysis/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
*/
protected function getRelationshipFromMethod($key, $camelKey)
{
$relations = $this->$camelKey();
if ( ! $relations instanceof Relation)
{
throw new LogicException('Relationship method must return an object of type '
. 'Illuminate\Database\Eloquent\Relations\Relation');
}
I thought there was something wrong with my data and so tried to create an empty record
$share = new RecordShare;
$share->save;
but this also failed with the same error. The function only gets pass if I remove this part totally.
what could be wrong? I tried to clear the cache, but still don't work.
One to one relationship provides the one-to-one relationship between the columns of different tables. For example, every user is associated with a single post or maybe multiple posts, but in this relationship, we will retrieve the single post of a user.
Laravel introduces a relationship: “HasOneThrough”. This is new in Laravel Development but, other framework uses this like “Rails”. The “HasOneThrough” relationship links models through a single intermediate relation. For example, if each group will have users and users will have their users history.
A one-to-one polymorphic relationship is a situation where one model can belong to more than one type of model but on only one association. A typical example of this is featured images on a post and an avatar for a user. The only thing that changes however is how we get the associated model by using morphOne instead.
I think change
$share->save;
to
$share->save();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With