Skip to content

Commit

Permalink
Merge pull request #8 from Mfalm3/ft-manage-property
Browse files Browse the repository at this point in the history
Ft manage property
  • Loading branch information
Mfalm3 authored Apr 8, 2021
2 parents a8ab1fd + 0c0f777 commit 1ac9460
Show file tree
Hide file tree
Showing 23 changed files with 5,414 additions and 50 deletions.
14 changes: 13 additions & 1 deletion .idea/dbnavigator.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions app/Http/Controllers/PropertyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Http\Controllers;

use App\Http\Requests\PropertyRequest;
use App\Models\Landlord;
use App\Models\Property;
use Illuminate\Http\Request;

Expand All @@ -14,7 +16,8 @@ class PropertyController extends Controller
*/
public function index()
{
return view('property.index');
$properties = Property::all();
return view('property.index', compact('properties'));
}

/**
Expand All @@ -24,19 +27,20 @@ public function index()
*/
public function create()
{
//
$owners = Landlord::all();
return view('property.create', compact('owners'));
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Http\Requests\PropertyRequest $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(PropertyRequest $request)
{
Property::create($request->all());
return response()->json('created property',201);
$request->save();
return redirect('/properties', 201)->with(['message'=> 'Created new property']);
}

/**
Expand All @@ -45,9 +49,9 @@ public function store(Request $request)
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
public function show(Property $property)
{
//
return view('property.show', compact('property '));
}

/**
Expand Down
41 changes: 41 additions & 0 deletions app/Http/Requests/PropertyRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Http\Requests;

use App\Models\Property;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;

class PropertyRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'landlord_id' => 'required|int',
'name' => 'required|string|max:255',
'location' => 'required|string|max:255',
];
}

public function save()
{
$uuid = (string) Str::uuid();

return Property::create(array_merge($this->request->all(), ['uuid'=>$uuid]));
}
}
13 changes: 11 additions & 2 deletions app/Models/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@ class Property extends Model
{
use HasFactory;

protected $fillable = ['landlord_id','name','location','account_number'];
protected $fillable = ['uuid','landlord_id','name','location','account_number'];
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
{
return 'uuid';
}

public function proprietor()
{
return $this->belongsTo(Landlord::class);
return $this->belongsTo(Landlord::class,'landlord_id');
}

public function houses()
Expand Down
1 change: 1 addition & 0 deletions database/factories/PropertyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function definition()

return [
'landlord_id' => $landlord->id,
'uuid' => $this->faker->uuid,
'name' => $this->faker->name.' '.$suffix[array_rand($suffix)],
'location' => $this->faker->address,
'account_number' => $this->faker->bankAccountNumber()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function up()
{
Schema::create('properties', function (Blueprint $table) {
$table->id();
$table->uuid('uuid')->unique();
$table->foreignId('landlord_id')->constrained();
$table->string('name');
$table->string('location');
Expand Down
Loading

0 comments on commit 1ac9460

Please sign in to comment.