<repo_name>Mohammedredabric/Info-Atlas-V1<file_sep>/app/Http/Controllers/PostController.php
<?php

namespace App\Http\Controllers;

use App\Http\Requests\PostRequest;
use App\Models\Post;
use Illuminate\Http\Request;
use function foo\func;

class PostController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $posts=Post::all();
        return view('blog.index',['posts'=>$posts]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('blog.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(PostRequest $request)
    {

        Post::create([
            'title'=> $request->input('title'),
            'sub_title'=> $request->input('sub_title'),
            'content'=> $this->getcontentwithsrc($request->input('content')),
            'user_id'=>auth()->id()
        ]);

        $request->session()->flash('post', 'has create ');
        return  redirect()->route('post.index');
    }

    public function getcontentwithsrc($content ){
        $detail=$content;

        $dom = new \DomDocument();

        $dom->loadHtml($detail, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

        $images = $dom->getElementsByTagName('img');

        foreach($images as $k => $img){

            $data = $img->getAttribute('src');

            list($type, $data) = explode(';', $data);

            list(, $data)      = explode(',', $data);

            $data = base64_decode($data);

            $image_name= "/upload/" . time().$k.'.png';

            $path = public_path() . $image_name;

            file_put_contents($path, $data);

            $img->removeAttribute('src');

            $img->setAttribute('src', $image_name);

        }

        return  $dom->saveHTML();
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $post=Post::find($id);
        return view('blog.edit',['post'=>$post]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(PostRequest $request, $id)
    {
        $post=Post::find($id);
        $post->update([
            'title'=> $request->input('title'),
            'sub_title'=> $request->input('sub_title'),
            'content'=> $this->getcontentwithsrc($request->input('content')),
            'user_id'=>auth()->id()
        ]);
        $request->session()->flash('post', 'has updated');
        return  redirect()->route('post.index');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $post=Post::find($id);
        $post->delete();
        return  redirect()->route('post.index')->with(['post'=>'has deleted ']);
    }
}
<file_sep>/app/Models/Amenity.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Amenity extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'icon_class',
        'name',
        'slug',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
    ];

    protected $hidden=['pivot','created_at','updated_at'];


    public function listings()
    {
        return $this->belongsToMany(\App\Models\Listing::class,'amenity_listing');
    }
}
<file_sep>/app/Models/City.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class City extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $table='cities';

    protected $fillable = [
        'name',
        'slug',
        'country_id',
    ];

    protected $hidden=[
        'created_at',
        'updated_at',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
    ];


    public function country(){
        return $this -> belongsTo('App\Models\Country','country_id','id');
    }
    public function listings(){
        return $this -> hasMany(\App\Models\Listing::class);
    }
}
<file_sep>/app/Models/Category.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'parebt',
        'icon_class',
        'name',
        'slug',
        'thumbnail',
        'created_at',
        'updated_at',
    ];

    protected $hidden=[
        'created_at',
        'updated_at',
        'pivot',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
    ];




    public function listings()
    {
        return $this->belongsToMany(\App\Models\Listing::class,'category_listing');
    }
}
<file_sep>/app/Http/Controllers/ReviewQualityController.php
<?php

namespace App\Http\Controllers;

use App\Http\Requests\ReviewQualityRequest;
use App\Models\ReviewQuality;
use http\Exception\InvalidArgumentException;
use Illuminate\Http\Request;

class ReviewQualityController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        $reviewwisequalities=ReviewQuality::all();
        return view('quality.index', compact('reviewwisequalities'));

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {

        return view('quality.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(ReviewQualityRequest $request)
    {
        $ReviewQuality=ReviewQuality::Create($request->all());
        $request->session()->flash('quality', $ReviewQuality->quality.'');
        return redirect()->route('quality.index');
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\ReviewQuality  $reviewQuality
     * @return \Illuminate\Http\Response
     */
    public function show(ReviewQuality $reviewQuality)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     */
    public function edit($id)
    {
       $quality = ReviewQuality::findOrFail($id);
      return view('quality.edit',compact('quality'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\ReviewQuality  $reviewQuality
     * @return \Illuminate\Http\Response
     */
    public function update(ReviewQualityRequest $request,$id)
    {

        $reviewQuality=ReviewQuality::findorfail($id);
        $reviewQuality->quality = $request->quality;
        $reviewQuality->rating_from =$request->rating_from;
        $reviewQuality->rating_to= $request->rating_to;
      $reviewQuality->save();
        $request->session()->flash('quality', $reviewQuality->quality.'');
        return redirect()->route('quality.index');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\ReviewQuality  $reviewQuality
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $ReviewQuality=ReviewQuality::findORfail($id);
        $ReviewQuality->delete();
        return redirect()->route('quality.index');
    }
}
<file_sep>/routes/web.php
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/



Route::group(['namespace' => 'frontend'], function(){
 Route::get('/' , 'HomeController@index');
});

Auth::routes(['verify' => true]);
Route::group(['middleware' => ['verified'], 'prefix' => 'admin'],function () {

    Route::Resource('category', 'CategoryController');

    Route::Resource('amenities', 'AmenitiesController');

    Route::Resource('city', 'CityController');

    Route::Resource('listing', 'ListingController');

    Route::Resource('post', 'PostController');

    Route::get('/claimed', 'ListingController@claimed');

    Route::post('/claimed/{id}', 'ListingController@active')->name("active.claimed");

    Route::Resource('quality', 'ReviewQualityController');

    Route::Resource('mailbox', 'MailBoxController');

    Route::Resource('user', 'UserController');

    Route::get('/settings/back','SettingsController@getbacksettings')->name('backsettings');

    Route::post('/settings/back','SettingsController@setbacksettings')->name('backsettings');

    Route::get('/settings/front','SettingsController@getfrontsettings')->name('frontsettings');

    Route::post('/settings/front','SettingsController@setfrontsettings')->name('frontsettings');

});

Route::get('/home', 'HomeController@index')
    ->name('home')
    ->middleware(['verified']);
<file_sep>/app/Models/ReviewQuality.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ReviewQuality extends Model
{

    protected $table='reviewwisequalities';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'rating_from',
        'rating_to',
        'quality',
    ];

    protected $hidden=[
        'created_at',
        'updated_at',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'rating_from' => 'float',
        'rating_to' => 'float',
    ];


    public function reviews()
    {
        return $this->hasMany(\App\Models\Review::class);
    }
}
<file_sep>/app/Http/Controllers/SettingsController.php
<?php

namespace App\Http\Controllers;

use App\Models\BackendSettings;
use App\Models\Country;
use App\Models\FrontendSettings;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;

class SettingsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getbacksettings()
    {
        $countries =Country::all();
        $Listsettings=BackendSettings::all();
        $settings=[];
        Foreach($Listsettings as $setting){
            $settings[$setting->type]=$setting->description;
        }
        return view('settings.back',compact(['countries','settings']));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function setbacksettings(Request $request){
        $settting=[
            'website_title'=>$request->input('website_title'),
            'system_title'=>$request->input('system_title'),
            'system_email'=>$request->input('system_email'),
            'address'=>$request->input('address'),
            'phone'=>$request->input('phone'),
            'country_id'=>$request->input('country_id'),
        ];

        foreach ($settting as $key =>$value){
            $back=BackendSettings::where('type',$key)->first();
            if ($back){
                $back->description=$value;
                $back->save();
            }
            else{
                $back=new BackendSettings();
                $back->type=$key;
                $back->description=$value;
                $back->save();
            }
        }
       // Config::set('APP_NAME','infoAtlas'); // default

        $request->session()->flash('stg','Saved');
        return redirect()->route('backsettings');

    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getfrontsettings()
    {
        $countries =Country::all();
        $Listsettings=FrontendSettings::all();
        $settings=[];
        Foreach($Listsettings as $setting){
            $settings[$setting->type]=$setting->description;
        }
        return view('settings.front',compact(['countries','settings']));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function setfrontsettings(Request $request){

        $settting=[
            'banner_title'=>$request->input('banner_title'),
            'banner_sub_title'=>$request->input('banner_sub_title'),
            'slogan'=>$request->input('slogan'),
            'facebook'=>$request->input('facebook'),
            'twitter'=>$request->input('twitter'),
            'about_us'=>$request->input('about_us'),
            'terms_and_condition'=>$request->input('terms_and_condition'),
            'privacy_policy'=>$request->input('privacy_policy'),
            'faq'=>$request->input('faq'),
        ];
        foreach ($settting as $key =>$value){

           if ($value !=""){
                $back=FrontendSettings::where('type',$key)->first();
                if ($back){
                    $back->description=$value;
                    $back->save();
                }
                else{
                    $back=new FrontendSettings();
                    $back->type=$key;
                    $back->description=$value;
                    $back->save();
                }
            }
        }
        $request->session()->flash('stg','Saved');
        return redirect()->route('frontsettings');

    }



}
<file_sep>/app/Models/Listing.php
<?php

namespace App\Models;

use App\TimeConfiguration;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Listing extends Model
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'code',
        'name',
        'description',
        'photos',
        'video_url',
        'video_provider',
        'tag',
        'adress',
        'email',
        'phone',
        'website',
        'social',
        'latitude',
        'longitude',
        'status',
        'listing_type',
        'listing_thumbnail',
        'listing_cover',
        'seo_meta_tags',
        'user_id',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'photos' => 'array',
        'social' => 'array',
    ];



    public $hidden=[
        'pivot',
        "created_at",
        "updated_at"
    ];

    ##################### Relations Start ############################
    public function user(){
        return $this->belongsTo(\App\Models\User::class);
    }

    public function city(){
        return $this -> belongsTo(\App\Models\City::class,'city_id');
    }

    public function time(){
        return $this -> hasOne(\App\Models\TimeConfiguration::class,'listing_id','id',"time_configuration");
    }

    public function reviews(){
        return $this -> hasMany(\App\Models\Review::class);
    }

    public function amenities(){
        return $this->belongsToMany(\App\Models\Amenity::class,'amenity_listing');
    }

    public function categories(){
        return $this->belongsToMany(\App\Models\Category::class,'category_listing');
    }
    ##################### Relations End ############################

}
<file_sep>/app/Models/CategoryListing.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CategoryListing extends Model
{
    protected $table="category_listing";
}
<file_sep>/app/Models/Country.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Country extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $table='countries';

    protected $fillable = [
        'name',
        'code',
        'dial_code',
        'currency_name',
        'currency_symbol',
        'currency_code',
        'slug',
    ];

    protected $hidden=[
        'created_at',
        'updated_at',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
    ];



    public function cities(){
        return $this -> hasMany('App\Models\City','country_id','id');
    }
}
<file_sep>/app/Models/AmenityListing.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class AmenityListing extends Model
{
    protected $table='amenity_listing';
}
<file_sep>/app/Http/Controllers/ListingController.php
<?php

namespace App\Http\Controllers;

use App\Http\Requests\ListingStoreRequest;
use App\Http\Requests\ListingUpdateRequest;
use App\Models\Amenity;
use App\Models\Category;
use App\Models\City;
use App\Models\Country;
use App\Models\Listing;
use App\Models\TimeConfiguration;
use App\Notifications\ListCreated;
use App\Notifications\ListPublished;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Notification;

class ListingController extends Controller
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $listings = Listing::select('id','name','status','city_id')
                    ->with(['City'=>function($q){
                $q->select('cities.id','cities.name','cities.country_id')
                ->with(['country'=>function($q){
                    $q->select('countries.id','countries.name');
            }]);}])
                    ->with(['categories'=>function($q){
                        $q->select('name');
        }])
                    ->where('status','Active')
                    ->get();
        return view('listing.index', compact(['listings']));
    }

    public function claimed(){
        $listings = Listing::select('id','name','status','city_id')
            ->with(['City'=>function($q){
                $q->select('cities.id','cities.name','cities.country_id')
                    ->with(['country'=>function($q){
                        $q->select('countries.id','countries.name');
                    }]);}])
            ->with(['categories'=>function($q){
                $q->select('name');
            }])
            ->where('status','Pendig')
            ->get();

        return view('listing.claimed', compact(['listings']));
    }

    public function active($id){
        $listing=Listing::find($id);
        $listing->status="Active";
        $listing->save();
        // Notification

        Notification::send($listing , new ListPublished($listing));
        return redirect()->route('listing.index')->with('listing', $listing->name. 'Listing has Achieved!');
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        $categories=Category::all();
        $cities=City::all();
        $amenities = Amenity::all();

        return view('listing.create' , compact(['categories','cities','amenities']));
    }

    /**
     * @param \App\Http\Requests\ListingStoreRequest $request
     * @return \Illuminate\Http\Response
     */
    public function store(ListingStoreRequest $request)
    {
        $listing = new Listing();
        $listing->code = substr(str_replace(['+', '/', '='], '', base64_encode(random_bytes(32))), 0, 32); // 32 characters, without /=+
        $listing->name=$request->input('name');
        $listing->description=$request->input('description');
        $listing->video_url=$request->input('video_url');
        $listing->video_provider='youtube';
        $listing->adress=$request->input('adress');
        $listing->email=$request->input('email');
        $listing->phone=$request->input('phone');
        $listing->website=$request->input('website');
        $listing->latitude=$request->input('latitude');
        $listing->longitude=$request->input('longitude');
        $listing->listing_type=$request->input('listing_type');
        $listing->city_id=$request->input('city');
        $listing->seo_meta_tags="Tag";
        $listing->tag="Tag";
        $listing->social=$request->input('social');
        $listing->user_id=auth()->id();
        $listing->listing_thumbnail=$this->SaveImage($request->file('listing_thumbnail'),'listing');
        $listing->listing_cover=$this->SaveImage($request->file('listing_cover'),'listing');
        $listing->photos=$this->SaveImage($request->file('Gallery'),'listing');
        $listing->status="Pendig";
        $listing->save();
        //
        $listing->amenities()->sync($request->input('amenities'));
        //
        $listing->categories()->sync($request->input('category'));
        //
        $timeConfiguration =new TimeConfiguration();
        $timeConfiguration->listing_id=$listing->id;
        $timeConfiguration->saturday=$request->input('time_configuration.SaturdayOpening').'-'.$request->input('time_configuration.SaturdayClosing');
        $timeConfiguration->sunday=$request->input('time_configuration.SundayOpening').'-'.$request->input('time_configuration.SundayClosing');
        $timeConfiguration->monday=$request->input('time_configuration.MondayOpening').'-'.$request->input('time_configuration.MondayClosing');
        $timeConfiguration->tuesday=$request->input('time_configuration.TuesdayOpening').'-'.$request->input('time_configuration.TuesdayClosing');
        $timeConfiguration->wednesday=$request->input('time_configuration.WednesdayOpening').'-'.$request->input('time_configuration.WednesdayClosing');
        $timeConfiguration->thursday=$request->input('time_configuration.ThursdayOpening').'-'.$request->input('time_configuration.ThursdayClosing');
        $timeConfiguration->friday=$request->input('time_configuration.FridayOpening').'-'.$request->input('time_configuration.FridayOpening');
        $timeConfiguration->save();
        //
        $request->session()->flash('listing', $listing->name);
        // Notification

        Notification::send($listing , new ListCreated($listing));

        return redirect()->route('listing.index');
    }

    public function SaveImage($photo,$folder){
        $file_extension= $photo->getClientOriginalExtension();
        $file_name=time().'.'.$file_extension;
        $path=$folder;
        $photo->move($path,$file_name);
        return $file_name;
    }


    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\Listing $listing
     * @return \Illuminate\Http\Response
     */

    public function show(Request $request, Listing $listing)
    {
        return view('listing.show', compact('listing'));
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\Listing $listing
     * @return \Illuminate\Http\Response
     */
    public function edit(Request $request,$id)
    {
        $listing=Listing::select()-> with(['time'=>function($q){
            $q->select('time_configuration.*');
        }])->where('id',$id)->with(['categories'=>function($q){
            $q->select('categories.id');
        }])->with(['amenities'=>function($q){
            $q->select('amenities.id');
        }])->first();
        $categories=Category::all();
        $cities=City::all();
        $amenities = Amenity::all();



        return view('listing.edit', compact(['categories','cities','amenities','listing']));
    }

    /**
     * @param \App\Http\Requests\ListingUpdateRequest $request
     * @param \App\Models\Listing $listing
     * @return \Illuminate\Http\Response
     */
    function checkIfLinkyouTube($url){
        $rx = '~
                ^(?:https?://)?              # Optional protocol
                 (?:www\.)?                  # Optional subdomain
                 (?:youtube\.com|youtu\.be)  # Mandatory domain name
                 /watch\?v=([^&]+)           # URI with video id as capture group 1
                 ~x';
        $has_match = preg_match($rx,  $url , $matches);
        if(isset($matches[1]) && $matches[1] != ''){
            return true;
        }else{
            return false;
        }
    }


    public function update(ListingUpdateRequest $request,$id)
    {
        $listing = Listing::Find($id);
        $listing->name=$request->input('name');
        $listing->description=$request->input('description');
        $listing->video_url=$request->input('video_url');
        $listing->video_provider='youtube';
        $listing->adress=$request->input('adress');
        $listing->email=$request->input('email');
        $listing->phone=$request->input('phone');
        $listing->website=$request->input('website');
        $listing->latitude=$request->input('latitude');
        $listing->longitude=$request->input('longitude');
        $listing->listing_type=$request->input('listing_type');
        $listing->city_id=$request->input('city');
        $listing->seo_meta_tags="Tag";
        $listing->tag="Tag";
        $listing->social=$request->input('social');
        if ($request->hasFile('listing_thumbnail'))
            $listing->listing_thumbnail=$this->SaveImage($request->file('listing_thumbnail'),'listing');
        if ($request->hasFile('listing_cover'))
            $listing->listing_cover=$this->SaveImage($request->file('listing_cover'),'listing');
        if ($request->hasFile('Gallery'))
            $listing->photos=$this->SaveImage($request->file('Gallery'),'listing');
        $listing->status="Active";
        $listing->save();
        //
        $listing->amenities()->sync($request->input('amenities'));
        //
        $listing->categories()->sync($request->input('category'));
        //

        $timeConfiguration =TimeConfiguration::where('listing_id',$listing->id)->first();
        $timeConfiguration->saturday=$request->input('time_configuration.saturdayOpening').'-'.$request->input('time_configuration.saturdayClosing');
        $timeConfiguration->sunday=$request->input('time_configuration.sundayOpening').'-'.$request->input('time_configuration.sundayClosing');
        $timeConfiguration->monday=$request->input('time_configuration.mondayOpening').'-'.$request->input('time_configuration.mondayClosing');
        $timeConfiguration->tuesday=$request->input('time_configuration.tuesdayOpening').'-'.$request->input('time_configuration.tuesdayClosing');
        $timeConfiguration->wednesday=$request->input('time_configuration.wednesdayOpening').'-'.$request->input('time_configuration.wednesdayClosing');
        $timeConfiguration->thursday=$request->input('time_configuration.thursdayOpening').'-'.$request->input('time_configuration.thursdayClosing');
        $timeConfiguration->friday=$request->input('time_configuration.fridayOpening').'-'.$request->input('time_configuration.fridayOpening');
        $timeConfiguration->save();


        $request->session()->flash('listing', $listing->name);
        return redirect()->route('listing.index');
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\Listing $listing
     * @return \Illuminate\Http\Response
     */
    public function destroy(Request $request, $id)
    {
        $listing = Listing::find($id);
        $listing->delete();
        $request->session()->flash('listing', $listing->name.' Deleted');
        return redirect()->route('listing.index');
    }
}
<file_sep>/app/Http/Controllers/CityController.php
<?php

namespace App\Http\Controllers;

use App\Http\Requests\CityStoreRequest;
use App\Http\Requests\CityUpdateRequest;
use App\Models\City;
use  App\Models\Country;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class CityController extends Controller
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
       /* $city=City::with('country')->find(6);
        $country=Country::with(['cities'=>function($q){
            $q->where('id', 1);
        }])->find(73);
        return $city ;
       */
        $cities=City::all();
        return view('city.index', compact('cities'));
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        $countries=Country::all();
        return view('city.create',compact('countries'));
    }

    /**
     * @param \App\Http\Requests\CityStoreRequest $request
     * @return \Illuminate\Http\Response
     */
    public function store(CityStoreRequest $request)
    {
        $city = City::create([
            'name' => $request->name,
            'slug' =>  strtolower($request->name),
            'country_id' =>  $request->country_id,
        ]);
        $request->session()->flash('city', $city->name.'');

        return redirect()->route('city.index');
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\City $city
     * @return \Illuminate\Http\Response
     */
    public function show(Request $request, City $city)
    {
        return view('city.show', compact('city'));
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\City $city
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $city=City::findOrfail($id);
        $countries=Country::all();
        return view('city.edit', compact(['city','countries']));
    }

    /**
     * @param \App\Http\Requests\CityUpdateRequest $request
     * @param \App\Models\City $city
     * @return \Illuminate\Http\Response
     */
    public function update(CityUpdateRequest$request,$id)
    {
        $city=City::findOrfail($id);

        $city->name=$request->input('name');
        $city->slug=Str::lower($request->input('name'));
        $city->country_id= $request->input('country_id');
        $city->save();
        $request->session()->flash('city', $city->name.'');
        return redirect()->route('city.index');


    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\City $city
     * @return \Illuminate\Http\Response
     */
    public function destroy(Request $request, City $city)
    {
        $city->delete();

        return redirect()->route('city.index');
    }
}
<file_sep>/app/Http/Controllers/AmenitiesController.php
<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;

use App\Http\Requests\AmenityStoreRequest;
use App\Http\Requests\AmenityUpdateRequest;
use App\Models\Amenity;
use Illuminate\Support\Str;

class AmenitiesController extends Controller
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $amenities = Amenity::all();

        return view('amenity.index', compact('amenities'));
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        return view('amenity.create');
    }

    /**
     * @param \App\Http\Requests\AmenitiesStoreRequest $request
     * @return \Illuminate\Http\Response
     */
    public function store(AmenityStoreRequest $request)
    {
        $amenity = Amenity::create([
            'icon_class' => $request->input("icon_class"),
            'name' => $request->input("name"),
            'slug' => Str::lower($request->input("name")),
        ]);
        $request->session()->flash('amenity', $amenity->name.'');
        return redirect()->route('amenities.index');
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\Amenity $amenity
     * @return \Illuminate\Http\Response
     */
    public function show(Request $request, Amenity $amenity)
    {
        return view('amenity.show', compact('amenity'));
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\Amenity $amenity
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $amenity= Amenity::findOrfail($id);
        return view('amenity.edit', compact('amenity'));
    }

    /**
     * @param \App\Http\Requests\AmenityUpdateRequest $request
     * @param \App\Models\Amenity $amenity
     * @return \Illuminate\Http\Response
     */
    public function update(AmenityUpdateRequest $request, $id)
    {
        $amenity= Amenity::findOrfail($id);
        $amenity->update([
            'icon_class' => $request->input("icon_class"),
            'name' => $request->input("name"),
            'slug' => Str::lower($request->input("name")),
        ]);
        $request->session()->flash('amenity', $amenity->name.'');
        return redirect()->route('amenities.index');
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\Amenity $amenity
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $amenity= Amenity::findOrfail($id);
        $amenity->delete();
        return redirect()->route('amenities.index');
    }
}
<file_sep>/app/Models/TimeConfiguration.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class TimeConfiguration extends Model
{

    protected $table="time_configuration";

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'monday',
        'tuesday',
        'wednesday',
        'thursday',
        'friday',
        'saturday',
        'sunday',
    ];

    public $hidden=[
        "created_at",
        "updated_at",
        "listing_id",
    ];

    public function listing(){
        return $this->hasMany(\App\Models\Listing::class);

    }

}
<file_sep>/database/migrations/2020_05_20_232839_create_listings_table.php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateListingsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('listings', function (Blueprint $table) {
            $table->id();
            $table->string('code');
            $table->string('name');
            $table->text('description');
            $table->json('photos');
            $table->string('video_url');
            $table->string('video_provider');
            $table->string('tag');
            $table->string('adress');
            $table->string('email');
            $table->string('phone');
            $table->string('website');
            $table->json('social');
            $table->string('latitude');
            $table->string('longitude');
            $table->string('status');
            $table->string('listing_type');
            $table->string('listing_thumbnail');
            $table->string('listing_cover');
            $table->string('seo_meta_tags');
            $table->foreignId('city_id');
            $table->foreign('city_id')->references('id')->on('cities')->onDelete('cascade');
            $table->foreignId('user_id');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('listings');
    }
}
<file_sep>/app/Http/Controllers/CategoryController.php
<?php

namespace App\Http\Controllers;

use App\Http\Requests\CategoryStoreRequest;
use App\Http\Requests\CategoryUpdateRequest;
use App\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Support\Str;


class CategoryController extends Controller
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $categories = Category::all();
        return view('category.index', compact('categories'));
    }



    /**
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        $categories = Category::where('parebt',0)->get();

        return view('category.create',compact('categories'));
    }

    /**
     * @param \App\Http\Requests\CategoryStoreRequest $request
     * @return \Illuminate\Http\Response
     */
    public function store(CategoryStoreRequest $request)
    {
        $category = Category::create([
            'parebt' =>$request->input("parebt") ,
            'icon_class' => $request->input("icon_class"),
            'name' => $request->input("name"),
            'thumbnail' =>$this->SaveImage($request->file('thumbnail'),'images') ,
            'slug' => Str::lower($request->input("name")),
        ]);

        $request->session()->flash('category', $category->name);

        return redirect()->route('category.index');
    }

    public function SaveImage($photo,$folder){
        $file_extension= $photo->getClientOriginalExtension();
        $file_name=time().'.'.$file_extension;
        $path=$folder;
        $photo->move($path,$file_name);
        return $file_name;
    }
    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\Category $category
     * @return \Illuminate\Http\Response
     */
    public function show(Request $request, Category $category)
    {
        return view('category.show', compact('category'));
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\Category $category
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $category = Category::findOrFail($id);
        $categories = Category::where('parebt',0)->get();
        return view('category.edit', compact(['category','categories']));
    }

    /**
     * @param \App\Http\Requests\CategoryUpdateRequest $request
     * @param \App\Models\Category $category
     * @return \Illuminate\Http\Response
     */
    public function update(CategoryUpdateRequest $request, Category $category)
    {
        if ($request->input('thumbnail')){
            $category->update([
                'parebt' =>$request->input("parebt") ,
                'icon_class' => $request->input("icon_class"),
                'name' => $request->input("name"),
                'thumbnail' =>$this->SaveImage($request->file('thumbnail'),'images') ,
                'slug' => Str::lower($request->input("name")),
            ]);
        }else{
            $category->update([
                'parebt' =>$request->input("parebt") ,
                'icon_class' => $request->input("icon_class"),
                'name' => $request->input("name"),
                'slug' => Str::lower($request->input("name")),
            ]);
        }
        $request->session()->flash('category', $category->name." has updated");
        return redirect()->route('category.index');
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \App\Models\Category $category
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $category=Category::findOrFail($id);
        $category->delete();

        return redirect()->route('category.index');
    }
}
<file_sep>/database/factories/ListingFactory.php
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use App\Models\Listing;
use Faker\Generator as Faker;

$factory->define(Listing::class, function (Faker $faker) {
    return [
        'code' => $faker->word,
        'name' => $faker->name,
        'description' => $faker->text,
        'photos' => '{}',
        'video_url' => $faker->word,
        'video_provider' => $faker->word,
        'tag' => $faker->word,
        'adress' => $faker->word,
        'email' => $faker->safeEmail,
        'phone' => $faker->phoneNumber,
        'website' => $faker->word,
        'social' => '{}',
        'latitude' => $faker->latitude,
        'longitude' => $faker->longitude,
        'status' => $faker->word,
        'listing_type' => $faker->word,
        'listing_thumbnail' => $faker->word,
        'listing_cover' => $faker->word,
        'seo_meta_tags' => $faker->word,
        'user_id' => $faker->word,
    ];
});
<file_sep>/app/Models/Review.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Review extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'review_comment',
        'reviewwisequality_id',
        'listing_id',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
    ];


    public function listing()
    {
        return $this->belongsTo(\App\Models\Listing::class);
    }

    public function reviewWiseQuality()
    {
        return $this->belongsTo(\App\Models\ReviewQuality::class);
    }
}
<file_sep>/database/factories/ReviewWiseQualityFactory.php
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use App\Models\ReviewWiseQuality;
use Faker\Generator as Faker;

$factory->define(ReviewWiseQuality::class, function (Faker $faker) {
    return [
        'rating_from' => $faker->randomFloat(0, 0, 9999999999.),
        'rating_to' => $faker->randomFloat(0, 0, 9999999999.),
        'quality' => $faker->word,
    ];
});
<file_sep>/tests/Feature/Http/Controllers/AmenitiesControllerTest.php
<?php

namespace Tests\Feature\Http\Controllers;

use App\Amenity;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use JMac\Testing\Traits\AdditionalAssertions;
use Tests\TestCase;

/**
 * @see \App\Http\Controllers\AmenitiesController
 */
class AmenitiesControllerTest extends TestCase
{
    use AdditionalAssertions, RefreshDatabase, WithFaker;

    /**
     * @test
     */
    public function index_displays_view()
    {
        $amenities = factory(Amenities::class, 3)->create();

        $response = $this->get(route('amenity.index'));

        $response->assertOk();
        $response->assertViewIs('amenity.index');
        $response->assertViewHas('amenities');
    }


    /**
     * @test
     */
    public function create_displays_view()
    {
        $response = $this->get(route('amenity.create'));

        $response->assertOk();
        $response->assertViewIs('amenity.create');
    }


    /**
     * @test
     */
    public function store_uses_form_request_validation()
    {
        $this->assertActionUsesFormRequest(
            \App\Http\Controllers\AmenitiesController::class,
            'store',
            \App\Http\Requests\AmenitiesStoreRequest::class
        );
    }

    /**
     * @test
     */
    public function store_saves_and_redirects()
    {
        $amenity = $this->faker->word;

        $response = $this->post(route('amenity.store'), [
            'amenity' => $amenity,
        ]);

        $amenities = Amenity::query()
            ->where('amenity', $amenity)
            ->get();
        $this->assertCount(1, $amenities);
        $amenity = $amenities->first();

        $response->assertRedirect(route('amenity.index'));
        $response->assertSessionHas('amenity.id', $amenity->id);
    }


    /**
     * @test
     */
    public function show_displays_view()
    {
        $amenity = factory(Amenities::class)->create();

        $response = $this->get(route('amenity.show', $amenity));

        $response->assertOk();
        $response->assertViewIs('amenity.show');
        $response->assertViewHas('amenity');
    }


    /**
     * @test
     */
    public function edit_displays_view()
    {
        $amenity = factory(Amenities::class)->create();

        $response = $this->get(route('amenity.edit', $amenity));

        $response->assertOk();
        $response->assertViewIs('amenity.edit');
        $response->assertViewHas('amenity');
    }


    /**
     * @test
     */
    public function update_uses_form_request_validation()
    {
        $this->assertActionUsesFormRequest(
            \App\Http\Controllers\AmenitiesController::class,
            'update',
            \App\Http\Requests\AmenitiesUpdateRequest::class
        );
    }

    /**
     * @test
     */
    public function update_redirects()
    {
        $amenity = factory(Amenities::class)->create();
        $amenity = $this->faker->word;

        $response = $this->put(route('amenity.update', $amenity), [
            'amenity' => $amenity,
        ]);

        $response->assertRedirect(route('amenity.index'));
        $response->assertSessionHas('amenity.id', $amenity->id);
    }


    /**
     * @test
     */
    public function destroy_deletes_and_redirects()
    {
        $amenity = factory(Amenities::class)->create();
        $amenity = factory(Amenity::class)->create();

        $response = $this->delete(route('amenity.destroy', $amenity));

        $response->assertRedirect(route('amenity.index'));

        $this->assertDeleted($amenity);
    }
}
<file_sep>/app/Http/Controllers/HomeController.php
<?php

namespace App\Http\Controllers;

use App\Models\Category;
use App\Models\City;
use App\Models\Listing;
use App\User;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        $listings= Listing::all()->Count();
        $categories= Category::all()->Count();
        $users= User::all()->Count();
        $cities=City::all()->count();
        return view('home',['listings'=>$listings,'categories'=>$categories,'user'=>$users,'cities'=>$cities]);
    }
}
<file_sep>/tests/Feature/Http/Controllers/CityControllerTest.php
<?php

namespace Tests\Feature\Http\Controllers;

use App\City;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use JMac\Testing\Traits\AdditionalAssertions;
use Tests\TestCase;

/**
 * @see \App\Http\Controllers\CityController
 */
class CityControllerTest extends TestCase
{
    use AdditionalAssertions, RefreshDatabase, WithFaker;

    /**
     * @test
     */
    public function index_displays_view()
    {
        $cities = factory(City::class, 3)->create();

        $response = $this->get(route('city.index'));

        $response->assertOk();
        $response->assertViewIs('city.index');
        $response->assertViewHas('cities');
    }


    /**
     * @test
     */
    public function create_displays_view()
    {
        $response = $this->get(route('city.create'));

        $response->assertOk();
        $response->assertViewIs('city.create');
    }


    /**
     * @test
     */
    public function store_uses_form_request_validation()
    {
        $this->assertActionUsesFormRequest(
            \App\Http\Controllers\CityController::class,
            'store',
            \App\Http\Requests\CityStoreRequest::class
        );
    }

    /**
     * @test
     */
    public function store_saves_and_redirects()
    {
        $city = $this->faker->word;

        $response = $this->post(route('city.store'), [
            'city' => $city,
        ]);

        $cities = City::query()
            ->where('city', $city)
            ->get();
        $this->assertCount(1, $cities);
        $city = $cities->first();

        $response->assertRedirect(route('city.index'));
        $response->assertSessionHas('city.id', $city->id);
    }


    /**
     * @test
     */
    public function show_displays_view()
    {
        $city = factory(City::class)->create();

        $response = $this->get(route('city.show', $city));

        $response->assertOk();
        $response->assertViewIs('city.show');
        $response->assertViewHas('city');
    }


    /**
     * @test
     */
    public function edit_displays_view()
    {
        $city = factory(City::class)->create();

        $response = $this->get(route('city.edit', $city));

        $response->assertOk();
        $response->assertViewIs('city.edit');
        $response->assertViewHas('city');
    }


    /**
     * @test
     */
    public function update_uses_form_request_validation()
    {
        $this->assertActionUsesFormRequest(
            \App\Http\Controllers\CityController::class,
            'update',
            \App\Http\Requests\CityUpdateRequest::class
        );
    }

    /**
     * @test
     */
    public function update_redirects()
    {
        $city = factory(City::class)->create();
        $city = $this->faker->word;

        $response = $this->put(route('city.update', $city), [
            'city' => $city,
        ]);

        $response->assertRedirect(route('city.index'));
        $response->assertSessionHas('city.id', $city->id);
    }


    /**
     * @test
     */
    public function destroy_deletes_and_redirects()
    {
        $city = factory(City::class)->create();

        $response = $this->delete(route('city.destroy', $city));

        $response->assertRedirect(route('city.index'));

        $this->assertDeleted($city);
    }
}
<file_sep>/app/Http/Controllers/UserController.php
<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use function MongoDB\BSON\toJSON;

class UserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $Users=User::all();
        return  view('user.index',compact('Users'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('user.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $data=$request->only('facebook','twitter','instgram','linkedin');
        $User=new User();
            $User->name=$request->input('name');
            $User->email=$request->input('email');
            $User->password= <PASSWORD>($request->input('password'));
            $User->phone=$request->input('phone');
            $User->address=$request->input('address');
            $User->websit= $request->input('websit');
            $User->about=$request->input('about');
            $User->link=$data;
            $User->save();
        $request->session()->flash('User', $User->name.'');
        return redirect()->route('user.index');    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $User =User::findORfail($id);
        return view('user.edit',compact('User'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $User=User::findOrfail($id);
        $data=$request->only('facebook','twitter','instgram','linkedin');
        $User->name=$request->input('name');
        $User->email=$request->input('email');
        $User->phone=$request->input('phone');
        $User->password=Hash::make($request->input('password'));
        $User->address=$request->input('address');
        $User->websit=$request->input('websit');
        $User->about=$request->input('about');
        $User->image=$request->input('image');
        $User->link= $data;
        $User->save();
        $request->session()->flash('User', $User->name.'');
        return  redirect()->route('user.index');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $User=User::findOrfail($id);
        $User->delete();
        return  redirect()->route('user.index');
    }
}
