Exemplo n.º 1
0
 public function update(Request $request)
 {
     $this->validate($request, ['city_id' => 'required|exists:locations,id,depth,' . Location::getCityDepth()], ['city_id' => '请至少输入城市']);
     if ($address = $this->addressManager->getAddressRepository()->whereOwner($this->shop())->first()) {
         $this->addressManager->update($address, $request->all());
     } else {
         $this->addressManager->createAddress($this->shop(), $request->all());
     }
     return $this->success('update');
 }
Exemplo n.º 2
0
 public function getLocations(Request $request)
 {
     $locationId = $request->input('depdrop_parents')[0];
     $location = Location::find($locationId);
     if (!$locationId or !$location) {
         return ['output' => []];
     }
     $locations = $location->children()->select('id', 'name')->get()->toArray();
     return ['output' => $locations];
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('locations', function (Blueprint $table) {
         // These columns are needed for Baum's Nested Set implementation to work.
         // Column names may be changed, but they *must* all exist and be modified
         // in the model.
         // Take a look at the model scaffold comments for details.
         // We add indexes on parent_id, lft, rgt columns by default.
         $table->increments('id');
         $table->integer('parent_id')->nullable()->index();
         $table->integer('lft')->nullable()->index();
         $table->integer('rgt')->nullable()->index();
         $table->integer('depth')->nullable();
         // Add needed columns here (f.ex: name, slug, path, etc.)
         // $table->string('name', 255);
         $table->string('name');
         $table->timestamps();
     });
     Location::buildTree($this->locations);
 }
Exemplo n.º 4
0
<?php

/**
 * Created by PhpStorm.
 * User: veoc
 * Date: 4/10/16
 * Time: 12:05 PM
 */
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(\App\Modules\AddressModule\Entities\Address::class, function (\Faker\Generator $faker) {
    $island = \App\Modules\AddressModule\Entities\Location::island()->inRandomOrder()->first();
    /** @var \App\Modules\AddressModule\Entities\Location $island */
    $province = $island->children()->inRandomOrder()->first();
    /** @var \App\Modules\AddressModule\Entities\Location $province */
    $city = $province->children()->inRandomOrder()->first();
    return ['recipient' => $faker->name, 'city_id' => $city->id, 'street' => $faker->streetAddress, 'postcode' => $faker->postcode, 'phone' => $faker->phoneNumber, 'primary' => false];
});
Exemplo n.º 5
0
 public function getCountry() : Location
 {
     return Location::root();
 }
Exemplo n.º 6
0
 public function test_can_update_address()
 {
     $user = $this->createUser();
     $address = $this->createAddress($user);
     $this->asUser($user)->visitAddressesIndexPage()->put($this->updateUrl($address), ['recipient' => '测试收件人', 'street' => '测试街道地址', 'phone' => '54321', 'city_id' => $cityId = Location::inRandomOrder()->city()->first()->id, 'postcode' => 'random-postcode'])->followRedirects()->seeSuccessMessage('修改成功')->seeAll('测试收件人', '测试街道地址', '54321', Location::find($cityId)->name, 'random-postcode');
 }