Skip to content
Snippets Groups Projects
Commit 078da490 authored by btalhaoui's avatar btalhaoui
Browse files

edit of migrations and added servers

parent 667fb2b1
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Auth;
use App\Models\Organizations;
use App\Models\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
......
......@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Organizations;
use App\Models\Server;
use Illuminate\Support\Facades\Auth;
class OrganizationController extends Controller
......@@ -16,4 +17,9 @@ class OrganizationController extends Controller
Auth::user()->organizations()->attach($org[0]->id);
return view("org/manage",['organizations' => Auth::user()->organizations()->get()]);
}
public function details($name){
$org = Organizations::where('name',$name)->get();
$servers = $org[0]->servers()->get();
return view("org/detail",['organization' => $org , 'servers' => $servers]);
}
}
......@@ -13,4 +13,8 @@ class Organizations extends Model
return $this->belongsToMany('App\Models\User','users_organizations', 'organization_id','user_id')
->withTimestamps();
}
public function servers()
{
return $this->hasMany('App\Models\Server', 'organization_id');
}
}
......@@ -8,6 +8,6 @@ class Sensors extends Moloquent
{
protected $connection = 'mongodb';
protected $collection = 'sensors';
protected $fillable = ['_id','content'];
protected $fillable = ['id','content'];
}
\ No newline at end of file
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Server extends Model
{
protected $fillable = ['name'];
public function organization()
{
return $this->belongsTo('App\Models\Organizations');
}
}
......@@ -6,6 +6,7 @@ use Illuminate\Database\Migrations\Migration;
class CreateSensorsTable extends Migration
{
protected $connection = 'mongodb';
/**
* Run the migrations.
*
......@@ -13,9 +14,9 @@ class CreateSensorsTable extends Migration
*/
public function up()
{
Schema::create('sensors', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
Schema::connection($this->connection)->table('sensors', function(Blueprint $collection)
{
$collection->index('id');
});
}
......@@ -26,6 +27,10 @@ class CreateSensorsTable extends Migration
*/
public function down()
{
Schema::dropIfExists('sensors');
Schema::connection($this->connection)->table('sensors', function(Blueprint $collection)
{
$collection->dropIndex('id');
});
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateServersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('servers', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('organization_id')->unsigned();
$table->foreign('organization_id')
->references('id')->on('organizations')
->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('servers');
}
}
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Your organizations</div>
@foreach ($organization as $org)
<p>{{ $org->name }}</p>
@endforeach
@foreach ($servers as $server)
<p>{{ $server->name }}</p>
@endforeach
</div>
</div>
</div>
</div>
@endsection
......@@ -19,4 +19,5 @@ Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/org', 'OrganizationController@index')->name('organizations');
Route::post('/org', 'OrganizationController@addOrg');
\ No newline at end of file
Route::post('/org', 'OrganizationController@addOrg');
Route::get('/org/{name}', ['uses' =>'OrganizationController@details']);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment