diff --git a/app/DeliveryInfo.php b/app/DeliveryInfo.php
index 264ee64..150dbaf 100644
--- a/app/DeliveryInfo.php
+++ b/app/DeliveryInfo.php
@@ -19,5 +19,10 @@ class Deliveryinfo extends Model
'contact_person_no',
];
+ public function company() {
+
+ return $this->belongsTo(App\Company);
+
+ }
}
diff --git a/app/Http/Controllers/DeliveryInfoController.php b/app/Http/Controllers/DeliveryInfoController.php
index 7602f62..66c697a 100644
--- a/app/Http/Controllers/DeliveryInfoController.php
+++ b/app/Http/Controllers/DeliveryInfoController.php
@@ -4,107 +4,100 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Deliveryinfo;
+use Auth;
class DeliveryinfoController extends Controller
{
+
/**
- * Display a listing of the resource.
+ * Display the specified delivery-info.
*
+ * @param int $id
* @return \Illuminate\Http\Response
*/
- public function index()
+ public function show(Deliveryinfo $id)
{
- $com_id = Deliveryinfo::all();
- return view('company.deliveryinfo.index');
+ $deliveryinfo = deliveryinfo::find($id);
+
+ return response()->json($deliveryinfo, 200);
}
/**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- //
- }
-
- /**
- * Store a newly created resource in storage.
+ * Store a newly delivery-info in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
- $deliveryinfo = Deliveryinfo::create($request->all());
+ $user = Auth::user();
- return response()->json($deliveryinfo, 201);
+ $deliveryinfo = new Deliveryinfo;
+ $deliveryinfo->branch = $request->input('branch');
+ $deliveryinfo->deli_info = $request->input('deli_info');
+ $deliveryinfo->address = $request->input('address');
+ $deliveryinfo->city = $request->input('city');
+ $deliveryinfo->postcode = $request->input('postcode');
+ $deliveryinfo->state = $request->input('state');
+ $deliveryinfo->country = $request->input('country');
+ $deliveryinfo->contact_person = $request->input('contact_person');
+ $deliveryinfo->contact_person_no = $request->input('contact_person_no');
+ $deliveryinfo->com_id = $user->company();
+ $deliveryinfo->save();
+
+ return response()->json(['deliveryinfo'=>$deliveryinfo],201);
}
/**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show(Deliveryinfo $com_id)
- {
- $deliveryinfo = deliveryinfo::find($com_id);
- return response()->json($deliveryinfo, 200);
-
- // return $delievryinfo;
- }
-
- /**
- * 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.
+ * Update the delivery-info.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
- public function update(Request $request, $com_id)
+ public function update(Request $request, $id)
{
- $com_id = Deliveryinfo::find($com_id);
-
- //$com_id->id = $request->input('id');
- $com_id->branch = $request->input('branch');
- $com_id->deli_info = $request->input('deli_info');
- $com_id->address = $request->input('address');
- $com_id->city = $request->input('city');
- $com_id->postcode = $request->input('postcode');
- $com_id->state = $request->input('state');
- $com_id->country = $request->input('country');
- $com_id->contact_person = $request->input('contact_person');
- $com_id->contact_person_no = $request->input('contact_person_no');
- $com_id->save();
+ $deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->where('id', $id)->firstOrFail();
- return response()->json(['com_id'=>$com_id],200);
+ if (!$deliveryinfo)
+ {
+ return response()->json(['message'=>'Access Denied!'], 404);
+ }
+
+ $deliveryinfo->branch = $request->input('branch');
+ $deliveryinfo->deli_info = $request->input('deli_info');
+ $deliveryinfo->address = $request->input('address');
+ $deliveryinfo->city = $request->input('city');
+ $deliveryinfo->postcode = $request->input('postcode');
+ $deliveryinfo->state = $request->input('state');
+ $deliveryinfo->country = $request->input('country');
+ $deliveryinfo->contact_person = $request->input('contact_person');
+ $deliveryinfo->contact_person_no = $request->input('contact_person_no');
+ $deliveryinfo->com_id = $user->company();
+ $deliveryinfo->save();
+
+ return response()->json(['deliveryinfo'=>$deliveryinfo],200);
}
/**
- * Remove the specified resource from storage.
+ * Remove the delivery-info.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
- public function destroy(Deliveryinfo $com_id)
+ public function destroy(Deliveryinfo $id)
{
-
- $com_id->delete($com_id);
+ $deliveryinfo = Deliveryinfo::where('com_id', Auth::user()->company())->where('id', $id)->firstOrFail();
- return response()->json($com_id, 204);
+ if (!$deliveryinfo)
+ {
+ return response()->json(['message'=>'Access Denied!'], 404);
+ }
+
+ $deliveryinfo->delete($id);
+
+ return response()->json($deliveryinfo, 204);
}
}
diff --git a/database/migrations/2018_04_25_024318_create_deliveryinfos_table.php b/database/migrations/2018_04_25_024318_create_deliveryinfos_table.php
index 9914edc..c8dfc96 100644
--- a/database/migrations/2018_04_25_024318_create_deliveryinfos_table.php
+++ b/database/migrations/2018_04_25_024318_create_deliveryinfos_table.php
@@ -27,6 +27,7 @@ class CreateDeliveryinfosTable extends Migration
$table->integer('contact_person_no');
$table->timestamps();
+
});
}
diff --git a/database/migrations/2018_06_11_033330_add_column_to_table_delivery_info.php b/database/migrations/2018_06_11_033330_add_column_to_table_delivery_info.php
new file mode 100644
index 0000000..adc10de
--- /dev/null
+++ b/database/migrations/2018_06_11_033330_add_column_to_table_delivery_info.php
@@ -0,0 +1,37 @@
+unsignedInteger('com_id');//FK wrn id
+ $table->foreign('com_id')
+ ->references('id')->on('companies')
+ ->onDelete('cascade');
+
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('deliveryinfos', function (Blueprint $table) {
+ //
+ });
+ }
+}
diff --git a/database/seeds/DeliveryInfoSeeder.php b/database/seeds/DeliveryInfoSeeder.php
new file mode 100644
index 0000000..9bab6a5
--- /dev/null
+++ b/database/seeds/DeliveryInfoSeeder.php
@@ -0,0 +1,16 @@
+\n' +
- ' \n' +
- ' \n' +
- ' \n' +
- ' Delivery 1\n' +
- ' \n' +
- ' ');
- },
- error: function (data) {
- alert('error');
- var errors = $.parseJSON(data.responseText);
- //console.log(errors.error);
- if (errors != null) {
- for (var i in errors.error) {
- //console.log(errors.error[i][0]);
- $('.alert').append(errors.error[i][0] + "
");
- }
- }
- $('.alert').show();
- }
+ // success: function (data) {
+ // //document.location.href = "home.html";
+ // $('#del-no').append(
+ // ''},
+ // error: function (data) {
+ // //alert('error');
+ // var errors = $.parseJSON(data.responseText);
+ // //console.log(errors.error);
+ // if (errors != null) {
+ // for (var i in errors.error) {
+ // //console.log(errors.error[i][0]);
+ // $('.alert').append(errors.error[i][0] + "
");
+ // }
+ // }
+ // $('.alert').show();
+ // }
- });
- })
+ //});
+ // })
})
diff --git a/routes/.api.php.swp b/routes/.api.php.swp
deleted file mode 100644
index a387b2a..0000000
Binary files a/routes/.api.php.swp and /dev/null differ
diff --git a/routes/.api_BASE_14556.php.swp b/routes/.api_BASE_14556.php.swp
deleted file mode 100644
index 9aca900..0000000
Binary files a/routes/.api_BASE_14556.php.swp and /dev/null differ
diff --git a/routes/.api_LOCAL_14556.php.swp b/routes/.api_LOCAL_14556.php.swp
deleted file mode 100644
index b8d71b5..0000000
Binary files a/routes/.api_LOCAL_14556.php.swp and /dev/null differ
diff --git a/routes/.api_REMOTE_14556.php.swp b/routes/.api_REMOTE_14556.php.swp
deleted file mode 100644
index 147e7e5..0000000
Binary files a/routes/.api_REMOTE_14556.php.swp and /dev/null differ
diff --git a/routes/api.php b/routes/api.php
index 19da9a5..3b8dadd 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -14,6 +14,7 @@ use App\Company;
*/
+
/* Routes for the DeliveryInfo in profile*/
Route::get('/company/deliveryinfo','DeliveryinfoController@index');
Route::get('/company/{com_id}/deliveryinfo','DeliveryinfoController@show');
@@ -51,6 +52,14 @@ Route::group(['middleware' => ['jwt.auth']], function() {
return response()->json(['user'=> $request->user()]);
});
+
+
+ /*Delivery-Info in profile menu*/
+ Route::get('/deliveryinfo/{com_id}','DeliveryinfoController@show');
+ Route::post('/deliveryinfo', 'DeliveryinfoController@store');
+ Route::put('/deliveryinfo/{com_id}', 'DeliveryinfoController@update');
+ Route::delete('/deliveryinfo/{com_id}', 'DeliveryinfoController@destroy');
+
});
diff --git a/routes/api_BACKUP_14556.php b/routes/api_BACKUP_14556.php
deleted file mode 100644
index 4be34e1..0000000
--- a/routes/api_BACKUP_14556.php
+++ /dev/null
@@ -1,46 +0,0 @@
-get('/user', function (Request $request) {
- return $request->user();
-});
-
-/* Routes for the DeliveryInfo in profile*/
-Route::get('/api/company/del-info','DeliveryInfoController@index');
-
-Route::get('/api/company/del-info','DeliveryInfoController@show');
-
-Route::post('/api/company/{com-id}/del-info', 'DeliveryInfoController@store');
-
-Route::put('/api/company/{com-id}/del-info', 'DeliveryInfoController@update');
-
-Route::delete('/api/company/{com-id}/del-info', 'DeliveryInfoController@delete');
-=======
-//Route::middleware('auth:api')->get('/user', function (Request $request) {
-// return $request->user();
-//});
-
-Route::post('register', 'AuthController@register');
-Route::post('login', 'AuthController@login');
-Route::post('recover', 'AuthController@recover');
-
-Route::group(['middleware' => ['jwt.auth']], function() {
- Route::get('logout', 'AuthController@logout');
- Route::get('test', function(){
- return response()->json(['foo'=>'bar']);
- });
-});
->>>>>>> 737c7da54f7707363ff7c7fe2f6b0d68f2f484f1
diff --git a/routes/api_BASE_14556.php b/routes/api_BASE_14556.php
deleted file mode 100644
index c641ca5..0000000
--- a/routes/api_BASE_14556.php
+++ /dev/null
@@ -1,18 +0,0 @@
-get('/user', function (Request $request) {
- return $request->user();
-});
diff --git a/routes/api_LOCAL_14556.php b/routes/api_LOCAL_14556.php
deleted file mode 100644
index d91cd5f..0000000
--- a/routes/api_LOCAL_14556.php
+++ /dev/null
@@ -1,29 +0,0 @@
-get('/user', function (Request $request) {
- return $request->user();
-});
-
-/* Routes for the DeliveryInfo in profile*/
-Route::get('/api/company/del-info','DeliveryInfoController@index');
-
-Route::get('/api/company/del-info','DeliveryInfoController@show');
-
-Route::post('/api/company/{com-id}/del-info', 'DeliveryInfoController@store');
-
-Route::put('/api/company/{com-id}/del-info', 'DeliveryInfoController@update');
-
-Route::delete('/api/company/{com-id}/del-info', 'DeliveryInfoController@delete');
diff --git a/routes/api_REMOTE_14556.php b/routes/api_REMOTE_14556.php
deleted file mode 100644
index aff41ed..0000000
--- a/routes/api_REMOTE_14556.php
+++ /dev/null
@@ -1,29 +0,0 @@
-get('/user', function (Request $request) {
-// return $request->user();
-//});
-
-Route::post('register', 'AuthController@register');
-Route::post('login', 'AuthController@login');
-Route::post('recover', 'AuthController@recover');
-
-Route::group(['middleware' => ['jwt.auth']], function() {
- Route::get('logout', 'AuthController@logout');
- Route::get('test', function(){
- return response()->json(['foo'=>'bar']);
- });
-});
\ No newline at end of file
diff --git a/tests/Unit/DeliveryinfoTest.php b/tests/Unit/DeliveryinfoTest.php
index 8d927f2..015b741 100644
--- a/tests/Unit/DeliveryinfoTest.php
+++ b/tests/Unit/DeliveryinfoTest.php
@@ -7,57 +7,35 @@ use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
+use Artisan;
+use App\Deliveryinfo;
class DeliveryinfoTest extends TestCase
{
- /**
- * A basic test example.
- *
- * @return void
- */
- public function testGET()
- {
- $response = $this->json('GET', '/api/company/deliveryinfo');
+ protected $company;
+ protected $user;
- $response->assertStatus(200);
+ public function setUp()
+ {
+ parent::setUp();
+ Artisan::call('db:seed');
+ $this->user = factory(User::class)->create();
+ $this->company = $this->user->each(function ($u) {
+ factory(Company::class)->create([
+ 'user_id' => $u->id,
+ ]);
+ });
}
- public function testPOST()
+ public function testPUT()
{
- $response = $this->json('POST', '/api/company/com_id/deliveryinfo', [
+
+ $response = $this->actingAs($this->company)
+ ->patchJson('/api/deliveryinfo', [
'branch' => 'Testing',
'deli_info' => 'Testing',
'address' => 'Testing',
- 'city' => 'Testing',
- 'postcode' => '12345',
- 'state' => 'Testing',
- 'country' => 'Testing',
- 'contact_person' => 'Testing',
- 'contact_person_no' => '12345',
-
- ]);
-
- $response->assertStatus(201);
- }
-
- public function testDELETE()
- {
- $response = $this->json('DELETE', '/api/company/4/deliveryinfo');
-
- $response->assertStatus(204);
- }
-
- public function testPUT()
- {
-
-
- $response = $this->json('PUT', '/api/company/1/deliveryinfo', [
-
- //'id' => '1',
- 'branch' => 'Ci',
- 'deli_info' => 'Testing',
- 'address' => 'Testing',
'city' => 'Test',
'postcode' => '12345',
'state' => 'Testing',
@@ -67,6 +45,15 @@ class DeliveryinfoTest extends TestCase
]);
- $response->assertStatus(200);
+ $response->assertStatus(200);
}
+
+ public function testDELETE()
+ {
+ $response = $this->json('DELETE', '/api/company/1/deliveryinfo');
+
+ $response->assertStatus(204);
+ }
+
+
}