Skip to content

Commit

Permalink
fixing change update
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadmoth committed Apr 22, 2020
1 parent b2e29c7 commit 328860b
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions app/Http/Controllers/ChildrensController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

class ChildrensController extends Controller
{


public $filds ;
/**
* Display a listing of the resource.
*
Expand All @@ -20,16 +23,10 @@ public function index()

//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{

$validator = Validator::make($request->all(), [
public function __construct()
{
$this->filds = [

'firstname' => "required|string",
'lastname' => "required|string",
Expand All @@ -41,7 +38,18 @@ public function store(Request $request)
'birthday' => 'required|date_format:"Y-m-d"|before_or_equal:' . date('d/m/Y'),
'srugerytypeid' => 'nullable|exists:tags,id',

]);
];
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{

$validator = Validator::make($request->all(),$this->filds);

if ($validator->passes()) {
$Childrens = new Childrens();
Expand Down Expand Up @@ -110,20 +118,8 @@ public function show(Request $request, Childrens $Childrens, $id)
public function update(Request $request, Childrens $Childrens, $id)
{
$request["id"] = $id;
$validator = Validator::make($request->all(), [
'id' => "exists:childrens,id",
'firstname' => "required|string",
'lastname' => "required|string",
'mothername' => "required|string",
"father" => "required|string",
'mobilephone' => 'required',
'phone' => 'required',
'birthplace' => 'required',
'birthday' => 'required|date_format:Y-m-d|before_or_equal:' . date('Y-m-d'),
'srugerytypeid' => 'required|exists:tags,id',


]);
$this->filds[] = [ 'id' => "exists:childrens,id"];
$validator = Validator::make($request->all(), $this->filds);

if ($validator->passes()) {
$Childrens = $Childrens::find($id);
Expand All @@ -136,7 +132,8 @@ public function update(Request $request, Childrens $Childrens, $id)
$Childrens->phone = $request->input("phone");

$Childrens->birthplace = $request->input("birthplace");
$Childrens->birthday = $request->input("birthday");
$Childrens->birthday = Carbon::parse($request->input("birthday"))->format('Y-m-d');

$Childrens->srugerytypeid = $request->input("srugerytypeid");
$Childrens->save();
return response()->json([
Expand Down

0 comments on commit 328860b

Please sign in to comment.