%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/ugotscom/kma/app/Http/Controllers/
Upload File :
Create Path :
Current File : /home/ugotscom/kma/app/Http/Controllers/PropertyController.php

<?php

namespace App\Http\Controllers;

use App\Property;
use App\PropertyImage;
use App\Leads;
use App\PropertyAmenity;
use App\PropertyFile;
use Carbon\Carbon;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Image;



class PropertyController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $data=Property::orderBy('properties.id', 'DESC')->where('properties.status',2)->leftJoin('locations','locations.location_id','=','properties.location')->leftJoin('clients','clients.id','=','properties.client_id')->select('properties.*','locations.location')->paginate(10);
        return response()->json($data);
    }

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

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'image' => 'required',
    ]);
    
    if($request->get('image'))
    {
        $file = new Filesystem();
        $image = $request->get('image');
        $name = time().'.' . explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
        $directory = 'images/property/';
        if ( $file->isDirectory(storage_path($directory)) )
        {
         \Image::make($image)->save(storage_path($directory).$name);
        
        }
         else
         {
             $file->makeDirectory(storage_path($directory), 755, true, true);
             \Image::make($image)->save(storage_path($directory).$name);
         }
    }
   
        $property = new Property;
        $property->client_id=$request->client_id;
        $property->title=$request->title;
        $property->description=$request->description;
        $property->property_for=$request->property_for;
        $property->property_type=$request->property_type;
        $property->price=$request->price;
        $property->latitude=$request->latitude;
        $property->longitude=$request->longitude;        
        $property->location=$request->location;   
        $property->carpet_area=$request->area;
        $property->bhk=$request->bhk;
        $property->project=$request->project;
        $property->featured_image= $name;
        $property->mmc=$request->mmc;
        $property->ref_id=$request->ref_id;
        $property->broker=$request->broker;
        $property->save();

        $propertyid=$property->id;

 
    

        $images=$request->get('images');
    
      
        if($images)
        { 
            foreach($images as $image){
               
                $string = Str::random(5);
                $name = $string.time().'.' . explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
                $directory = 'images/property/'.$propertyid.'/';
               
                if ( $file->isDirectory(storage_path($directory)) )
                {
                 \Image::make($image)->save(storage_path($directory).$name);
                
                }
                 else
                 {
                     $file->makeDirectory(storage_path($directory), 755, true, true);
                     \Image::make($image)->save(storage_path($directory).$name);
                 }
                echo $name;              
                $propertyimages = new PropertyImage;
                $propertyimages->property_id=$property->id;
                $propertyimages->image=$name;
                $propertyimages->status=1;
                $propertyimages->save();


           
             }
            
           
            
        }
        $amenities=$request->checkedAmenties;
        if($amenities){

            foreach($amenities as $amenity){
                
                $newamenity=new PropertyAmenity;
                $newamenity->property_id=$property->id;
                $newamenity->amenties_id=$amenity;
                $newamenity->status=1;
                $newamenity->save();


            }
          
            

        }
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Property  $property
     * @return \Illuminate\Http\Response
     */
    public function show(Property $property)
    {
        //
        $users=Property::all();
        return $users;
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Property  $property
     * @return \Illuminate\Http\Response
     */
    public function edit(Property $property)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Property  $property
     * @return \Illuminate\Http\Response
     */
    public function update($id, Request $request)
    {
        //
        $user = Property::findOrFail($id);

        $user->update($request->all());
  
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Property  $property
     * @return \Illuminate\Http\Response
     */
    public function destroy(Property $property)
    {
        //
    }
    public function searchproperty(Request $request){
        $property_for=$request->property_for;
        $location=$request->location;
        $min=$request->min;
        $max=$request->max;
        $property_type=$request->property_type;
     
   
        if (is_array($location) ) {
            $users=Property::where('property_for',$property_for)            
            ->leftJoin('locations','locations.location_id','=','properties.location')
            ->leftJoin('furnishing','furnishing.id','=','properties.Furnishing')
            ->select('properties.*','locations.*', 'furnishing.furnishing')
            ->whereIn('properties.location',$location)
            ->when($property_type, function ($query) use ($property_type) {
                return $query->where('property_type',$property_type);
            })
            ->when($min, function ($query) use ($min,$max) {
                return $query->whereBetween('price',[$min,$max]);
            })
            ->where('properties.available_status',2)
            ->paginate(10);
           
       }

     else{
        $users=Property::where('property_for',$property_for)
        ->leftJoin('locations','locations.location_id','=','properties.location')
       ->leftJoin('furnishing','furnishing.id','=','properties.Furnishing')
       ->select('properties.*','locations.*', 'furnishing.furnishing')
       ->where('properties.available_status',2)
        ->where('properties.location',$location)->paginate(10);
                  
     }
     
//$users=Property::orderBy('id', 'DESC')->paginate(20;)
     return response()->json($users);
    }
    public function formSubmit(Request $request)

    {
    	$imageName = time().'.'.$request->image->getClientOriginalExtension();
        $request->image->move(public_path('images'), $imageName);      
    	return response()->json(['success'=>'You have successfully upload image.']);

    }
    public function propertybyid($id){
        $properties=Property::where('id',$id)->get();
        return response()->json($properties);
    }
    public function clientproperties($id){
        $properties=Property::where('client_id',$id)->get();
        return response()->json($properties);
    }
    public function clientpropertiesbyid($id){
        $properties=Property::where('client_id',$id)->leftJoin('locations','locations.location_id','=','properties.location')->paginate(5);
        return response()->json($properties);
    }
    public function uploadFiles(Request $request) {
       
            
                    
                    $filename = $file->getClientOriginalName();
            
                    $path = hash( 'sha256', time());
            
                    if(Storage::disk('uploads')->put($path.'/'.$filename,  File::get($file))) {
            
                        $input['filename'] = $filename;
                        $input['mime'] = $file->getClientMimeType();
                        $input['path'] = $path;
                        $input['size'] = $file->getClientSize();
                        $file = FileEntry::create($input);
            
                        return response()->json([
                            'success' => true,
                            'id' => $file->id
                        ], 200);
                    }
            
                    return response()->json([
                        'success' => false
                    ], 500);
    }
    public function pendingApproval()
    {
        //
        $data=Property::orderBy('id', 'DESC')->leftJoin('locations','locations.location_id','=','properties.location')->where('status',1)->paginate(5);
        return response()->json($data);
    }
    public function managedProperties()
    {
        //
        $data=Property::orderBy('id', 'DESC')->where('status',4)->paginate(5);
        return response()->json($data);
    }
    public function updateStatus($id){

        Property::whereid($id)->update([
            'status' => 2
        ]);
    }
    public function updatestatusavailable($id,Request $request){

        Property::whereid($id)->update([
            'available_status' => $request->avstatus
        ]);
    }
    public function homecare($id,Request $request){

        Property::whereid($id)->update([
            'homecare_status' => $request->homecare
        ]);
    }
    
    public function managedProperty($id){

        Property::whereid($id)->update([
            'status' => 4
        ]);
    }
    public function uploadFile(Request $request)
    {
      $images=$request->get('images');
    
      
        if($images)
        { 
            foreach($images as $image){
               
                $string = Str::random(5);
                $name = $string.time().'.' . explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
                \Image::make($image)->save(storage_path('images/property').$name);
                
                echo $name;              
                

           
             }
            
           
            
        }
     
      
    }
    public function propertyimages(){
        $users=PropertyImage::latest()->paginate(1);
        return $users;

    }
    public function propertyimagebyid($id){
        $propertiesimages=PropertyImage::where('property_id',$id)->get();
        return response()->json($propertiesimages);
    }
    public function totalcount(){
        $users['total']=Property::all()->count();
        $users['available']=Property::where('available_status',2)->where('status',2)->count();
        $propertytype = [1, 2, 3,4];
        $commercial=[5,6,7,8,9];
        $users['residential']=Property::whereIn('property_type',$propertytype)->where('status',2)->count();
        $users['commercial']=Property::whereIn('property_type',$commercial)->where('status',2)->count();
        $users['rent']=Property::where('property_for',1)->where('status',2)->where('available_status',2)->count();
        $users['sale']=Property::where('property_for',2)->where('status',2)->where('available_status',2)->count();
        $users['apartment']=Property::where('property_type',1)->where('status',2)->count();
        $users['house']=Property::where('property_type',2)->where('status',2)->count();
        $users['gated']=Property::where('property_type',3)->where('status',2)->count();
        $users['rland']=Property::where('property_type',4)->where('status',2)->count();   
        $users['offices']=Property::where('property_type',9)->where('status',2)->count(); 
        $users['itpark']=Property::where('property_type',5)->where('status',2)->count(); 
        $users['retail']=Property::where('property_type',6)->where('status',2)->count();  
        $users['cland']=Property::where('property_type',7)->where('status',2)->count();
        $users['warehouse']=Property::where('property_type',8)->where('status',2)->count();         
        return $users;
    }
    public function amenitiesbyid($id){
        $properties=PropertyAmenity::where('property_id',$id)->leftJoin('amenities','amenities.id','=','property_amenities.id')->get();
        return response()->json($properties);
    }
    public function searchquery(){
        if($search =\Request :: get('q')){

            $users=Property::where(function($query) use ($search){
            $query->where('property_name','LIKE',"%$search%")
                  ->orwhere ('title','LIKE',"%$search%")  
                  ->orwhere ('id','LIKE',"%$search%")  
                  ->orwhere ('description','LIKE',"%$search%")                
            ;})->paginate(50);
            }
         else {
            $users=Property::latest()->paginate(50);
         }   
        return $users;
    }
    public function homecareproperties()
    {
        //
        $data=Property::orderBy('properties.id', 'DESC')->where('properties.homecare_status',2)->leftJoin('locations','locations.location_id','=','properties.location')->leftJoin('clients','clients.id','=','properties.client_id')->select('properties.*','locations.location')->paginate(10);
        return response()->json($data);
    }

    public function brokerproperties(){
        $data=Property::orderBy('properties.id', 'DESC')->leftJoin('locations','locations.location_id','=','properties.location')->leftJoin('clients','clients.id','=','properties.client_id')->select('properties.*','locations.location')->where('broker',1)->paginate(10);
        return response()->json($data);
    }
    public function propertyfiles(Request $request){
            
        $request->validate([
                 'file.*' => 'required|file|mimes:ppt,pptx,doc,docx,pdf,xls,xlsx|max:2048',
          ]);

        $fileUpload = new PropertyFile;

        if($request->file()) {
            $file_name = time().'_'.$request->file->getClientOriginalName();
            $file_path = $request->file('file')->storeAs('propertydoc', $file_name, 'public');
            $fileUpload->maintenance_id= $request->maintenance_id;
            $fileUpload->file_name=$file_name;
            $fileUpload->name = $request->file_name;
            $fileUpload->type = $request->type;
            $fileUpload->path = '/storage/' . $file_path;
            $fileUpload->save();

          //  $this->sendstatusNotification('File Uploaded');
            return response()->json(['success'=>'File uploaded successfully.']);
        }
   }
   public function expiredProperties()
   {
       //
       
       $data=Property::orderBy('id', 'DESC')->leftJoin('locations','locations.location_id','=','properties.location')->where('updated_at', '<=', Carbon::now()->subDays(90)->toDateTimeString())->paginate(50);
       return response()->json($data);
   }

   public function getDocs($id){
    $propertyFiles=PropertyFile::where('maintenance_id',$id)->get();
    return response()->json($propertyFiles);
}
public function propertyfiledelete($id){
    PropertyFile::where('id',$id)->delete(); 
}
public function propertylocationwise($id){
    $properties = Property::where('property_for',$id)->leftJoin('locations','locations.location_id','=','properties.location')->groupBy('properties.location')
->selectRaw('count(*) as total, locations.location')
->orderBy('total','DESC')
->limit(10)
->get();
return response()->json($properties);
}
public function propertytypewise($id){
  
    $properties['rent'] = Property::where('location',$id)->where('properties.property_for',1)->leftJoin('property_type','property_type.property_type_id','=','properties.property_type')->groupBy('properties.property_type')
->selectRaw('count(*) as total, property_type.property_for_type')
->orderBy('total','DESC')
->limit(10)
->get();
return response()->json($properties);
}
public function propertytypewisesale($id){
  
    $properties['rent'] = Property::where('location',$id)->where('properties.property_for',2)->leftJoin('property_type','property_type.property_type_id','=','properties.property_type')->groupBy('properties.property_type')
->selectRaw('count(*) as total, property_type.property_for_type')
->orderBy('total','DESC')
->limit(10)
->get();
return response()->json($properties);
}
}

Zerion Mini Shell 1.0