Propiedad model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Propiedad extends Model{
protected $table = 'Propiedades';
protected $fillable = [
'titulo',
'descripcion',
'ubicacion',
'tipoInmueble',
'tipoPublicacion',
'antiguedad',
'dormitorios',
'cocheras',
'banios',
'toilette',
'valorPropiedad',
'provincia',
'ciudad',
'superficie'];
public function user(){
return $this->belongsTo(User::class);
}
}
PropiedadesTable
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class PropiedadesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(){
Schema::create('propiedades', function (Blueprint $table) {
$table->increments('id');
$table->string('titulo');
$table->string('descripcion');
$table->string('ubicacion');
$table->string('tipoInmueble');
$table->string('tipoPublicacion');
$table->integer('antiguedad');
$table->integer('dormitorios');
$table->integer('cocheras')->nullable();
$table->integer('banios');
$table->integer('toilette')->nullable();
$table->integer('valorPropiedad');
$table->string('provincia');
$table->string('ciudad');
$table->integer('user_id')->unsigned();
$table->integer('superficie');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('propiedades');
}
}
PropiedadController
<?php
namespace App\Http\Controllers;
use App\Propiedad;
use Illuminate\Http\Request;
class PropiedadController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request){
$propiedades = Propiedad::where('user_id', $request->user()->id);
return view ('Profile.ver-propiedades', [
'propiedades' => $propiedades
]);
}
public function mostrarPropiedades(){
$propiedades = Propiedad::all();
return view('home');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('Profile.agregarPropiedad');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->user()->propiedades()->create($request->all());
return redirect('profile#propiedades');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
return redirect('profile#propiedades');
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
public function verPropiedadesUsuario(Request $request){
$props = Propiedad::where('user_id', $request->get('user_id'))->get();
return view('Profile/ver-propiedades', ['propiedades' => $props]);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
Lo otro ya guarda TODO solo me falta lo que me traigo por la api