1: <?php
2:
3: namespace App;
4:
5: use Illuminate\Database\Eloquent\Model;
6: use Illuminate\Support\Facades\DB;
7: class AdLocation extends Model
8: {
9: 10: 11: 12: 13:
14: protected $table = 'ad_location';
15:
16:
17: 18: 19: 20: 21:
22: protected $fillable = [
23: 'ad_id',
24: 'location',
25: 'lat',
26: 'lng'
27: ];
28:
29: public $timestamps = false;
30:
31: public function ad(){
32: return $this->belongsTo('App\Ad');
33: }
34: public static function insertLocals($id,$location){
35: foreach($location as $local){
36: DB::table('ad_location')->insert([
37: 'ad_id' => $id,
38: 'location' => $local['city'],
39: 'lat' => $local['lat'],
40: 'lng' => $local['lng'],
41: ]);
42: }
43: }
44:
45: public static function deleteLocals($id){
46: DB::table('ad_location')->where('ad_id',$id)->delete();
47: }
48: }