diff --git a/app/Company.php b/app/Company.php index 237e5cc..f64bc1a 100644 --- a/app/Company.php +++ b/app/Company.php @@ -14,4 +14,10 @@ class Company extends Model { return $this->belongsTo('App\User'); } + + public function deliveryinfo() { + + return $this->hasMany('App\Deliveryinfo'); + + } } diff --git a/app/DeliveryInfo.php b/app/DeliveryInfo.php index 150dbaf..8aeacae 100644 --- a/app/DeliveryInfo.php +++ b/app/DeliveryInfo.php @@ -17,12 +17,13 @@ class Deliveryinfo extends Model 'country', 'contact_person', 'contact_person_no', + 'com_id' ]; public function company() { - return $this->belongsTo(App\Company); + return $this->belongsTo('App\Company'); - } + } } diff --git a/app/Http/Controllers/DeliveryInfoController.php b/app/Http/Controllers/DeliveryInfoController.php index 66c697a..4a4cdd4 100644 --- a/app/Http/Controllers/DeliveryInfoController.php +++ b/app/Http/Controllers/DeliveryInfoController.php @@ -33,6 +33,7 @@ class DeliveryinfoController extends Controller { $user = Auth::user(); + $deliveryinfo = new Deliveryinfo; $deliveryinfo->branch = $request->input('branch'); $deliveryinfo->deli_info = $request->input('deli_info'); @@ -43,7 +44,7 @@ class DeliveryinfoController extends Controller $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->com_id = $user->company()->first()->id; $deliveryinfo->save(); return response()->json(['deliveryinfo'=>$deliveryinfo],201); diff --git a/config/database.php b/config/database.php index c2ea412..d1ce98b 100644 --- a/config/database.php +++ b/config/database.php @@ -58,7 +58,7 @@ return [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), - 'database' => 'forunittest', + 'database' => 'testingizyim', 'username' => 'root', 'password' => '', 'unix_socket' => env('DB_SOCKET', ''), diff --git a/database/factories/DeliveryinfoFactory.php b/database/factories/DeliveryinfoFactory.php deleted file mode 100644 index 3a4c0fb..0000000 --- a/database/factories/DeliveryinfoFactory.php +++ /dev/null @@ -1,18 +0,0 @@ -define(App\Deliveryinfo::class, function (Faker $faker) { - return [ - 'id' => $faker, - 'branch' => $faker->text, - 'deli_info' => $faker->sentence, - 'address' => $faker->text, - 'city' => $faker->text, - 'postcode' => $faker->text, - 'state' => $faker->text, - 'country' => $faker->text, - 'contact_person' => $faker->name, - 'contact_person_no' => $faker->text, - ]; -}); diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 0cb5c57..6d66f56 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -16,10 +16,13 @@ use Faker\Generator as Faker; $factory->define(App\User::class, function (Faker $faker) { return [ + + + + 'name' => $faker->name, 'email' => $faker->unique()->safeEmail, 'password' => bcrypt(str_random(10)), // secret - 'phone' => $faker->unique()->randomDigit, 'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret diff --git a/database/seeds/CompanySeeder.php b/database/seeds/CompanySeeder.php new file mode 100644 index 0000000..b35e062 --- /dev/null +++ b/database/seeds/CompanySeeder.php @@ -0,0 +1,35 @@ +insert([ + + 'id' => '999', + 'company_name'=>'testing', + 'registration_no'=>'testing', + 'tax_no'=>'testing', + 'tel_no'=>'12345', + 'fax'=>'12345', + 'address'=>'testing', + 'city'=>'testing', + 'postcode'=>'12345', + 'state'=>'testing', + 'country'=>'testing', + 'contact_person'=>'testing', + 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'user_id' => '2' + + ]); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 4a81932..1ce7e13 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -13,5 +13,7 @@ class DatabaseSeeder extends Seeder { $this->call(LaratrustSeeder::class); $this->call(UsersTableSeeder::class); + //$this->call(DeliveryInfoSeeder::class); + $this->call(CompanySeeder::class); } } diff --git a/database/seeds/DeliveryInfoSeeder.php b/database/seeds/DeliveryInfoSeeder.php index 9bab6a5..88638fb 100644 --- a/database/seeds/DeliveryInfoSeeder.php +++ b/database/seeds/DeliveryInfoSeeder.php @@ -1,6 +1,7 @@ insert([ + + 'id' => '999', + 'branch' => 'Testing', + 'deli_info' => 'Testing', + 'address' => 'Testing', + 'city' => 'Test', + 'postcode' => '12345', + 'state' => 'Testing', + 'country' => 'Testing', + 'contact_person' => 'Testing', + 'contact_person_no' => '12345', + 'created_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'), + 'com_id' => '999' + + ]); } } diff --git a/public/.htaccess b/public/.htaccess index b75525b..f38755e 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -13,6 +13,9 @@ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] + #providing token + RewriteCond %{HTTP:Authorization} ^(.*) + RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d diff --git a/public/home.html b/public/home.html index 40941f4..56536b9 100644 --- a/public/home.html +++ b/public/home.html @@ -1308,8 +1308,10 @@ $('#del-info').click(function() { $.ajax({ type: "POST", - url: "api/company/deliveryinfo", + url: "api/deliveryinfo", //headers: {"Authorization": 'Bearer' + localStorage.getItem('token')}, + //headers: {"Authorization": 'Bearer' + localStorage.getItem('token')}, + headers: {"Authorization": 'Bearer' + localStorage.getItem('token')}, data: { branch:$('#branch').val(), deli_info: $('#branchText1').val(), @@ -1322,7 +1324,7 @@ contact_person_no:$('#branchText8').val() }, success: function(data) { - document.location.href="home.html"; + //document.location.href="home.html"; }, error: function(data) { var errors = $.parseJSON(data.responseText); @@ -1339,10 +1341,24 @@ }) - // $('#del-inf').click(function() { - // $.ajax({ - // type: "GET", - // url: "api/company/deliveryinfo", + $('#del-inf').click(function() { + var $infos= $('#del-inf'); + + $.ajax({ + type: "GET", + url: "api/deliveryinfo/1", + headers: {"Authorization": 'Bearer' + localStorage.getItem('token')}, + success: function (infos) + { + $each(infos, function (i, info) { + + $infos.append('
  • Branch:'+ info.branch +',DelInfo:'+ info.deli_info +',Address:'+ info.address +',City:'+ info.city +'' + + ',PostCode:'+ info.postcode +',State:' +info.state +',Country:' +info.country +',ContactPerson:' +info.contact_person +'' + + ',ContactPersonNo:' +info.contact_person_no +'
  • '); + }); + } + }); + }); // success: function (data) { diff --git a/routes/api.php b/routes/api.php index 3b8dadd..e36d6c4 100644 --- a/routes/api.php +++ b/routes/api.php @@ -15,13 +15,9 @@ use App\Company; -/* Routes for the DeliveryInfo in profile*/ -Route::get('/company/deliveryinfo','DeliveryinfoController@index'); -Route::get('/company/{com_id}/deliveryinfo','DeliveryinfoController@show'); -Route::post('/company/deliveryinfo', 'DeliveryinfoController@store'); -Route::put('/company/{com_id}/deliveryinfo', 'DeliveryinfoController@update'); -Route::delete('/company/{com_id}/deliveryinfo', 'DeliveryinfoController@destroy'); +/* Routes for the DeliveryInfo in profile*/ + @@ -37,6 +33,10 @@ Route::delete('/company/{com_id}/deliveryinfo', 'DeliveryinfoController@destroy' Route::post('register', 'AuthController@register'); + +/* Authentication */ + + /* Authentication */ Route::post('login', 'AuthController@login'); @@ -60,13 +60,22 @@ Route::group(['middleware' => ['jwt.auth']], function() { Route::put('/deliveryinfo/{com_id}', 'DeliveryinfoController@update'); Route::delete('/deliveryinfo/{com_id}', 'DeliveryinfoController@destroy'); -}); + + + /* Company */ + + + + + + + /* Company */ Route::patch('/company', 'CompanyController@update'); //update company information Route::post('/company/company_profile/', 'CompanyController@companyProfile');//upload company profile picture Route::post('/company/reg_cert/', 'CompanyController@regCert'); //upload registration certificaate - +}); diff --git a/tests/Unit/DeliveryinfoTest.php b/tests/Unit/DeliveryinfoTest.php index 015b741..d2f59d4 100644 --- a/tests/Unit/DeliveryinfoTest.php +++ b/tests/Unit/DeliveryinfoTest.php @@ -1,13 +1,14 @@ actingAs($this->company) ->patchJson('/api/deliveryinfo', [ - 'branch' => 'Testing', + 'branch' => 'Test', 'deli_info' => 'Testing', 'address' => 'Testing', 'city' => 'Test', @@ -48,12 +49,12 @@ class DeliveryinfoTest extends TestCase $response->assertStatus(200); } - public function testDELETE() - { - $response = $this->json('DELETE', '/api/company/1/deliveryinfo'); + // public function testDELETE() + // { + // $response = $this->json('DELETE', '/api/deliveryinfo'); - $response->assertStatus(204); - } + // $response->assertStatus(204); + // } }