%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/PropertyController2.php

<?php

namespace App\Http\Controllers;

use App\Property;
use App\PropertyImage;
use App\Leads;
use App\PropertyAmenity;
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('id', 'DESC')->where('status',2)->leftJoin('locations','locations.location_id','=','properties.location')->paginate(5);
        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'))
    {
        $image = $request->get('image');
        $name = time().'.' . explode('/', explode(':', substr($image, 0, strpos($image, ';')))[1])[1];
        \Image::make($request->get('image'))->save(public_path('images/').$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->save();

        echo $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];
                \Image::make($image)->save(public_path('images/').$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]);
            })
            ->paginate(20);
           
       }

     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.location',$location)->paginate(20);
                  
     }
     
//$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 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(public_path('images/').$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('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)->count();
        $users['sale']=Property::where('property_for',2)->where('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 ('description','LIKE',"%$search%")                
            ;})->paginate(50);
            }
         else {
            $users=Property::latest()->paginate(50);
         }   
        return $users;
    }
}

Zerion Mini Shell 1.0