Below is my application \ Cart.php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Cart extends Model {
use SoftDeletes;
protected $table = 'cart';
protected $fillable = ['sess','uid'];
}
Below is my application \ Http \ Controllers \ CartController.php
public function cart($id=0, $act, Request $request)
{
$sessId = Session::getId();
switch($act){
case 'Add':
$quantity = $request->only('p_quantity');
$data = $request->except('p_quantity');
$cartId = Cart::firstOrCreate(['sess' => $sessId,'status' => 1]);
break;
case 'Delete':
break;
}
return response()->json(['success' => true,'message' => 'Success', 'act' => $act, 'id' => $id ,'data' => $data, 'quantity'=> $quantity, 'cart'=>$cartId->id]);
}
I want to check the database if the session key exists in the cart.sess table, otherwise create a new one and get the identifier.
The question is when it continues to create a new duplicate session in the database.

Can I find out where I made a mistake?
thank
UPDATE [2015-05-27 16:02]:
After the table, I TRUNCATE and set the sess field to Unique, first send it in order, and then send it the following error:

UPDATE [2015-05-27 16:16]
The code I use to create the database is:
CREATE TABLE IF NOT EXISTS `cart` (
`id` int(11) NOT NULL,
`uid` int(11) DEFAULT NULL,
`sess` varchar(40) NOT NULL,
`status` int(11) DEFAULT '1',
`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`deleted_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;