Good, I would like to know how you can help me in the following, I have a publication, but I want to have two buttons, draft and publish, and when they give a draft it is saved in a status and the client can see what I create and then I can give the button publish is updated to published status,
I have a column in my data database type integer-> status
but i wanted to know if you can help me build the function in my controller
controller properties
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Propertie;
use App\Departament;
use App\Municipality;
use App\Characteristic;
use App\Detail;
use App\Offer_type;
use App\Property_type;
use App\Space;
use App\ImgProperties;
use Storage;
use Illuminate\Support\Str;
use File;
use Session;
use App\Image; // what is this? using the model
class PropertyController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
/* ---- Conditions, and inquiries about scopes, to show the results in the index ----*/
/* $name = $request->get('name');*/
if ($request->p_type) {
$properties = Propertie::typeof($request->p_type)->get();
} elseif ($request->sorttype) {
$properties = Propertie::sorttype($request->sorttype)->get();
} else {
$properties = Propertie::orderBy('id', 'ASC')
/* ->name($name)*/
->paginate(5);
}
$property_type = Property_type::all();
$spaces = Space::all();
return view('properties.index', compact('properties', 'property_type', 'spaces'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$offer = Offer_type::all()->pluck('name', 'id');
$detail = Detail::all()->pluck('name', 'id');
$characteristics = Characteristic::all()->pluck('name', 'id');
$property_type = Property_type::all()->pluck('name', 'id');
$departamento = Departament::all();
$spaces = Space::all()->pluck('name', 'id');
//return response()->json();
return view('properties.create', compact('departamento', 'offer', 'detail', 'characteristics', 'property_type', 'spaces', 'properties'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
/*--from this session you start to save the properties with all their attributes --*/
// dd( $request->file('images') );
$properti = new Propertie;
$detail = new Detail;
$detail->antiquity = $request->antiquity;
$detail->furnished = $request->furnished;
$detail->floor = $request->floor;
$detail->save();
$properti->details_id = $detail->id;
$properti->name = $request->name;
$properti->code = $request->code;
$properti->price = $request->price;
$properti->description = $request->description;
$properti->departaments_id = $request->departaments;
$properti->municipalities_id = $request->municipalities;
$properti->property_type_id = $request->type_property;
$properti->offer_type_id = $request->type;
$properti->details_id = $detail->id;
$properti->lat = $request->lat;
$properti->lng = $request->lng;
$properti->address = $request->address;
$properti->save();
if($request->hasfile('images'))
{
$i = 1;
foreach($request->file('images') as $item_img ){
$img = new Image;
$ext = $item_img->getClientOriginalExtension(); // getting extension
$newFile = $properti->id . '-' . time().'-'.$i.'.' .$ext; // changing file name to property id + current time stemp + esxtension.
$item_img->move('images',$newFile);
$img->name = $newFile;
$img->property_id = $properti->id;
$img->save();
$i++;
};
}
$piso_id = $properti->id;
$space = new Space;
$space->property_id = $piso_id;
$space->bedrooms = $request->bedrooms;
$space->bathrooms = $request->bathrooms;
$space->parking = $request->parking;
$space->area = $request->area;
$space->save();
$properti->spaces_id = $space->id;
foreach ($request->input('characteristic') as $characteristic) {
$charc = new Characteristic;
$charc->property_id = $piso_id;
$charc->characteristic = $characteristic;
$charc->save();
}
Session::flash('message', 'Se ha registrado su propiedad De forma exitosa');
return redirect()->action('PropertyController@index',compact('name'));
// return view('properties.index',compact('properties'));
}
public function getDepartments() {
$departments = Departament::all();
return response()->json($departments);
}
public function getMunicipalities(Request $request, $id)
{
if ($request->ajax())
{
$municipalitys = Municipality::municipalities($id);
return response()->json($municipalitys);
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$departamento = Departament::all();
$property = Propertie::with('Images')->findOrFail($id);
return view('properties.show',compact('property','id','departamento'));
}
public function showpreview($id)
{
$departamento = Departament::all();
$property = Propertie::findOrFail($id);
return response()->json($property);
}
public function showimage($id)
{
$image = Image::all();
return response()->json($image);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$departamento = Departament::all();
$properti = Propertie::findOrFail($id);
return view('properties.edit', compact('departamento', 'properti', 'municipalities'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$properti = Propertie::findOrFail($id);
$image = Propertie::find($id)->img_properties;
flash("Se ha actualizado " . $properti->name . " De forma exitosa ")->success();
return redirect()->route('properties.index', compact('image'));
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$properti = Propertie::findOrFail($id);
$properti->delete();
flash('Se ha Eliminado el plan ' . $properti->name . ' Ha sido borrado de forma exitosa ')->important();
return redirect()->action('PropertyController@index');
}
}
I have these two buttons in my view create
<button type="submit" class="btn btn-primary my-1">Crear</button>
<button type="submit" class="btn btn-primary my-1">Draft</button>
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/38JlPg7
via IFTTT
Aucun commentaire:
Enregistrer un commentaire