Exemplo n.º 1
0
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required', 'description' => '', 'unique_id' => 'required|unique:stations,unique_id', 'lat' => 'required', 'lng' => 'required']);
     $station = new \App\Station();
     $station->name = $request->input('name');
     $station->description = $request->input('description', '');
     $station->unique_id = $request->input('unique_id');
     $station->lat = $request->input('lat');
     $station->lng = $request->input('lng');
     $station->user_id = $request->user()->id;
     $station->save();
     $tags = [];
     foreach ($request->get('tags', []) as $tag) {
         if ($tag == "") {
             continue;
         }
         $t = \App\Tag::where('name', $tag)->first();
         if (!$t) {
             $t = new \App\Tag();
             $t->name = strtolower($tag);
             $t->save();
         }
         $tags[] = $t->id;
     }
     $station->tags()->sync(array_unique($tags));
     return redirect('backend/stations/' . $station->id);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function getIndex()
 {
     $stationModel = new \App\Station();
     $stations = $stationModel->all();
     $relayModel = new \App\Relay();
     $relays = $relayModel->all();
     return array('stations' => $stations, 'relays' => $relays);
     return json_encode(array('success' => 'test', 'message' => 'my test'));
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $positions = ['Banja Luka' => ['lat' => '44.7785709', 'lng' => '17.1361267'], 'Gradiska' => ['lat' => '45.1413827', 'lng' => '17.2405045'], 'Srbac' => ['lat' => '45.0965046', 'lng' => '17.5078242'], 'Mrkonjic Grad' => ['lat' => '44.4149267', 'lng' => '17.0813563'], 'Laktasi' => ['lat' => '44.9075524', 'lng' => '17.2817192'], 'Bijeljina' => ['lat' => '44.760706', 'lng' => '19.1697901'], 'Mostar' => ['lat' => '43.3395487', 'lng' => '17.786221'], 'Sarajevo' => ['lat' => '43.3395487', 'lng' => '17.786221'], 'Pale' => ['lat' => '43.8174955', 'lng' => '18.5493794'], 'Prijedor' => ['lat' => '44.9828959', 'lng' => '16.6664094'], 'Prnjavor' => ['lat' => '44.8688679', 'lng' => '17.6325089'], 'Novi Sad' => ['lat' => '45.2722076', 'lng' => '19.7794008']];
     $users = App\User::get();
     foreach ($users as $user) {
         $stations = factory(App\Station::class, 2)->make();
         foreach ($stations as $station) {
             $position = array_shift($positions);
             $station->lat = $position['lat'];
             $station->lng = $position['lng'];
         }
         $user->stations()->saveMany($stations);
     }
     $tags = App\Tag::get();
     $stations = App\Station::get();
     foreach ($stations as $station) {
         $aerometrics = factory(App\Aerometric::class, 20)->make();
         $station->tags()->sync($tags->random(3)->lists('id')->toArray());
         $station->aerometrics()->saveMany($aerometrics);
     }
 }
Exemplo n.º 4
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return Redirect::action('StationsController@index');
});
Route::model('phones', 'Phone');
Route::model('stations', 'Station');
Route::bind('phones', function ($value, $route) {
    return App\Phone::whereSlug($value)->first();
});
Route::bind('stations', function ($value, $route) {
    return App\Station::whereSlug($value)->first();
});
Route::resource('stations', 'StationsController');
Route::resource('stations.phones', 'PhonesController');
Exemplo n.º 5
0
    });
    Route::get('/stations', function () {
        return App\Station::all();
    });
    Route::post('/station', function () {
        $station = App\Station::where('unique_id', '=', request()->input('unique_id', ''))->firstOrFail();
        $aerometric = new App\Aerometric();
        $aerometric->station_id = $station->id;
        foreach (array_keys(config('aerometrics.properties')) as $property) {
            $aerometric->{$property} = request()->input($property, '0.0');
        }
        $aerometric->save();
        return ['success' => true];
    });
    Route::get('/station', function () {
        $station = App\Station::where('unique_id', '=', request()->input('unique_id', ''))->firstOrFail();
        $aerometric = new App\Aerometric();
        $aerometric->station_id = $station->id;
        foreach (array_keys(config('aerometrics.properties')) as $property) {
            $aerometric->{$property} = request()->input($property, '0.0');
        }
        $aerometric->save();
        return ['success' => true];
    });
});
Route::group(['middleware' => 'web'], function () {
    Route::group(['middleware' => 'auth', 'prefix' => 'backend'], function () {
        Route::get('/', 'BackendController@index');
        Route::resource('stations', 'Backend\\StationsController');
        Route::get('stations/{stations}/import', 'Backend\\StationsController@getImport');
        Route::post('stations/{stations}/import', 'Backend\\StationsController@postImport');