Files
izyim-api/app/Http/Controllers/CompanyController.php
T
2018-05-02 16:34:39 +08:00

155 lines
4.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Company;
use Image;
class CompanyController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
return view ('home');
}
/**
* 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)
{
//
//$company = new Company;
// if($request->hasFile('avatar'))
// {
// $avatar = $request->file('avatar');
// $filename = time() . '.' . $avatar->getClientOriginalExtension();
// Image::make($avatar)->resize(300,300)->save(public_path('/uploads/company_profile/'.$filename));
// }
// else
// {
// return response()->json(['message'=>'Document not found']);
// }
$input = $request->all();
if($file = $request->file('company_profile'))
{
$name = $file->getClientOriginalName();
$img_file = $request->file('company_profile');
Image::make($img_file)->resize(300,300)->save(public_path('uploads\company_profile\hello.jpg'));
return $img_file;
// $file->move('uploads/company_profile/', $img_file);
$input['company_profile'] = $name;
}
Company::create($input);
//Company::create(request()->all());
//dd(request()->all());
// return redirect('/');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$company = Company::find($id);
if (!$company)
{
return response()->json(['message'=>'Document not found'],200);
}
//$warehouse->address='juhgfd';
if($request->hasFile('avatar'))
{
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save(public_path('/uploads/company_profile/'.$filename));
}
$company->company_name=$request->input('company_name');
$company->registration_no=$request->input('registration_no');
$company->tax_no=$request->input('tax_no');
$company->tel_no=$request->input('tel_no');
$company->fax=$request->input('fax');
$company->address=$request->input('address');
$company->city=$request->input('city');
$company->postcode=$request->input('postcode');
$company->state=$request->input('state');
$company->country=$request->input('country');
$company->contact_person=$request->input('contact_person');
$company->save();
return response()->json(['warehouse'=>$company],200);
// $product = Company::findOrFail($productId);
// $product->update($request->all());
// $product->company_name = 'imagepath';
// $product->save();
//return response()->json($product, 200);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
public function uploadImage($request)
{
// if($request->hasFile('avatar'))
// {
// $avatar = $request->file('avatar');
// $filename = time() . '.' . $avatar->getClientOriginalExtension();
// Image::make($avatar)->resize(300,300)->save(public_path('/uploads/company_profile/'.$filename));
// }
}
}