Hi, My Eloquent Model is here-
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class UserAdvertisementView extends Model
{
protected $primaryKey = null;
public $incrementing = false;
public $timestamps = false;
protected $table = 'user_add_views'; //Table Name
protected $fillable = [
'user_id',
'add_id',
'total_view'
];
public function user()
{
return $this->hasOne('App\User','user_id');
}
public function advertisement()
{
return $this->hasOne('App\advertisement','add_id');
}
//Scope Query for view count
/**
* Scope a query for a mass Assignment
*
* @return \Illuminate\Database\Eloquent\Builder
*/
/*
public function scopeInsertData($query,$project_id,$data)
{
$bulk_data = array();
foreach ($data as $value)
{
array_push(
$bulk_data,
array(
'project_id' => $project_id,
'feature_id' => $value
)
);
}
return $query->insert($bulk_data);
}
*/
}
And Controller like this-
public function map_try($id)
{
$result = UserAdvertisementView::where('user_id','=',Auth::user()->id)
->where('add_id',$id)
->first();
if($result)
{
$result->total_view = 90;
$result->save();
return $result;
}
else
{
UserAdvertisementView::create(array(
'user_id'=> Auth::user()->id,
'add_id'=> $id,
'total_view'=>1
));
return 'OK';
}
}
Problem is, it don't return anything, not even an error or any response.
Can anyone please help?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community