I have a controller where I'm trying to figure if a profile for building already exists, if not then return the view that creates it.
The $propertyid is passed with the URL.
public function create($propertyid, $propertytype)
{
// if this property has a profile, then execute the show function
if (Profile::where('propertyid', '=', $propertyid {
return $this->show($propertyid);
} else {
// create the profile
// pass the propertyid and propertytype variable to the create view blade file
return view('profile.create', [
'propertyid' => $propertyid,
'propertytype' => $propertytype
]);
}
}
I get a:
"syntax error, unexpected 'return' (T_RETURN)"
$profile = Profile::where('propertyid', '=', $propertyid)->first();
if ( is_nulL($profile) ) {
}
if ( $profile = Profile::where('propertyid', '=', $propertyid)->first()) {
// If profile exists will assign profile to $profile and you have it available here
}
if ( count( $profile ) === 1 ) {
}
public function create($propertyid, $propertytype)
{
// if this property has a profile, then show the profile
$profile = Profile::where('propertyid', '=', $propertyid)->first();
if ( $profile->isNotEmpty() ) {
return $this->show($propertyid);
}
if ( $profile->isEmpty() ) {
// create the profile
// pass the propertyid and propertytype variable to the view controller
return view('profile.create', [
'propertyid' => $propertyid,
'propertytype' => $propertytype
]);
}
}
Now I get:
"Call to a member function isNotEmpty() on null"