xxxxxxxxxx
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Phone extends Model
{
/**
* Get the user that owns the phone.
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}
xxxxxxxxxx
try:
print("I will try to print this line of code")
except:
print("I will print this line of code if an error is encountered")
xxxxxxxxxx
try:
print("I will try to print this line of code")
except ERROR_NAME:
print(f"I will print this line of code if error {ERROR_NAME} is encountered")
xxxxxxxxxx
try:
# tests code that may cause errors
except Exception as e:
# handles the error
else:
# executed when there is no error
finally:
# always executed
xxxxxxxxxx
try:
Age = int(input("Your Age:- "))
except ValueError:
print("Age not in Intger form")
xxxxxxxxxx
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Phone extends Model
{
/**
* Get the user that owns the phone.
*/
public function user()
{
return $this->belongsTo('App\Models\User');
}
}
xxxxxxxxxx
try: #try to do the following
print("Hi there")
except: #If what is meant to happen in (try) fails, do this.
print("A error happened with the code above")
xxxxxxxxxx
/**
* Insert the signature
*
* @param Request $request
* @return ...
*/
public function store( Request $request ) {
// your validation
$signature->users()->attach( $request->input('user_id') );
// return
}
xxxxxxxxxx
/**
* Update the signature with the particular id
*
* @param $id
* @param Request $request
* @return ...
*/
public function update( $id, Request $request ) {
// your validation
$signature->users()->sync( $request->input('user_id') );
// return
}