- Laravel Version: 5.5.
- PHP Version: 7.0.0
I'm trying to perform the following operation using Laravel Eloquent ORM
IF record exists then the UPDATE
the record
ELSE INSERT
new record by creating new
Model instance
Save them using save()
method. However, using new
keyword I guess giving me the following error.
"Parse error: syntax error, unexpected 'New' (T_NEW), expecting identifier (T_STRING)"
app/Http/Controllers/NewFolder/FlightController.php
<?php
namespace app\Http\Controllers\New\FlightController;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Flight;
class FlightController extends Controller
{
public function store(Request $request)
{
$flight = Flight::where('email', $request->email) ?? new Flight;
$flight->name = $request->name;
$flight->save();
app/Models/Flight.php
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class Flight extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'table_name';
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3oEgMVG
via IFTTT
Aucun commentaire:
Enregistrer un commentaire