post method

This commit is contained in:
Asif
2018-06-20 11:04:46 +08:00
13 changed files with 123 additions and 47 deletions
+6
View File
@@ -14,4 +14,10 @@ class Company extends Model
{
return $this->belongsTo('App\User');
}
public function deliveryinfo() {
return $this->hasMany('App\Deliveryinfo');
}
}
+3 -2
View File
@@ -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');
}
}
}
@@ -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);
+1 -1
View File
@@ -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', ''),
@@ -1,18 +0,0 @@
<?php
use Faker\Generator as Faker;
$factory->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,
];
});
+4 -1
View File
@@ -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
+35
View File
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Seeder;
use Carbon\Carbon;
class CompanySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('companies')->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'
]);
}
}
+2
View File
@@ -13,5 +13,7 @@ class DatabaseSeeder extends Seeder
{
$this->call(LaratrustSeeder::class);
$this->call(UsersTableSeeder::class);
//$this->call(DeliveryInfoSeeder::class);
$this->call(CompanySeeder::class);
}
}
+18 -1
View File
@@ -1,6 +1,7 @@
<?php
use Illuminate\Database\Seeder;
use Carbon\Carbon;
class DeliveryInfoSeeder extends Seeder
{
@@ -11,6 +12,22 @@ class DeliveryInfoSeeder extends Seeder
*/
public function run()
{
//
DB::table('deliveryinfos')->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'
]);
}
}
+3
View File
@@ -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
+22 -6
View File
@@ -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('<li>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 +' </li>');
});
}
});
});
// success: function (data) {
+17 -8
View File
@@ -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
});
+10 -9
View File
@@ -1,13 +1,14 @@
<?php
namespace Tests\Unit\Deliveryinfo;
namespace Test\API;
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Facades\Storage;
use Artisan;
use App\User;
use App\Company;
use App\Deliveryinfo;
class DeliveryinfoTest extends TestCase
@@ -33,7 +34,7 @@ class DeliveryinfoTest extends TestCase
$response = $this->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);
// }
}