Commit cf37198a by Angel MAS

crud users

parents
/vendor/
{
"name": "onestartup/user-admin",
"description": "Module for create user in dashboard",
"type": "library",
"license": "Apache-2.0",
"authors": [
{
"name": "Angel MAS",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require": {},
"autoload": {
"psr-4": {"Onestartup\\UserAdmin\\": "src"}
}
}
<?php
namespace Onestartup\UserAdmin;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Yajra\Datatables\Datatables;
use App\User;
class AdminUserController extends Controller
{
public function list()
{
$roles = [1 => 'Admin', 2 => 'Editor'];
return view('user-admin::list')->with('roles', $roles);
}
public function storeUser(Request $request)
{
$user = new User($request->all());
$user->password = bcrypt($request->password);
$user->save();
return redirect()->back()->with('message_success', 'Se registro correctamente');
}
public function show($id)
{
$user = User::find($id);
$roles = [1 => 'Admin', 2 => 'Editor'];
return view('user-admin::edit')
->with('roles', $roles)
->with('user', $user);
}
public function update(Request $request, $id)
{
$user = User::find($id);
$user->fill($request->all());
$user->save();
return redirect()->back()->with('message_success', 'Se registro correctamente');
}
public function destroy($id)
{
$user = User::find($id);
$user->delete();
return redirect()->route('user.list')->with('message_success', 'Se eliminó correctamente');
}
public function datatable()
{
$users = User::select(['id','name','email', 'short_bio','rol_id','created_at'])->orderBy('id', 'desc');
return Datatables::of($users)
->addColumn('details_url', function ($user) {
return "<a href='".route('user.show',$user->id)."'>Ver Detalle</a>";
})
->rawColumns(['details_url'])
->make();
}
}
<?php
namespace Onestartup\UserAdmin;
use Illuminate\Support\ServiceProvider;
class UserAdminProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
include __DIR__.'/routes.php';
$this->loadMigrationsFrom(__DIR__.'/migrations');
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->make('Onestartup\UserAdmin\AdminUserController');
$this->loadViewsFrom(__DIR__.'/views', 'user-admin');
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddShortBioToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('short_bio', 555)->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('short_bio');
});
}
}
<?php
Route::group(['middleware' => ['web', 'auth', 'is_admin']], function(){
Route::get('admin/user','Onestartup\UserAdmin\AdminUserController@list')->name('user.list');
Route::get('admin/user/datatable','Onestartup\UserAdmin\AdminUserController@datatable')->name('user.datatable');
Route::get('admin/user/{id}/show','Onestartup\UserAdmin\AdminUserController@show')->name('user.show');
Route::post('admin/user/store','Onestartup\UserAdmin\AdminUserController@storeUser')->name('user.store');
Route::put('admin/user/{id}/update','Onestartup\UserAdmin\AdminUserController@update')->name('user.update');
Route::delete('admin/user/{id}/destroy','Onestartup\UserAdmin\AdminUserController@destroy')->name('user.destroy');
});
@extends('layouts.admin.admin-layout')
@section('content')
<div class="row">
<div class='col-md-10 offset-1'>
<div class='box'>
<div class='box-header dark'>
<h2>
Actualizar datos
</h2>
</div>
<div class='box-body'>
<div class="row">
<div class="col-md-8 offset-2">
{!! Form::model($user,['route'=> ['user.update',$user->id],"method"=>"PUT"]) !!}
@include('user-admin::fields')
<br>
<div class="row">
<div class="col-md-6">
{!! Form::submit('Actualizar', ['class'=>'btn btn-block btn-primary']) !!}
{!! Form::close() !!}
</div>
<div class="col-md-6">
{!! Form::open(['route'=> ['user.destroy', $user->id],'method'=>'DELETE'])!!}
<button type='submit' class="btn btn-block btn-danger" onclick='return confirm("¿Estas seguro que deseas eliminar este USUARIO?")'>Eliminar este usuario</button>
{!! Form::close()!!}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
\ No newline at end of file
{!! Form::label('name', 'Nombre', ['class'=>'control-label']) !!}
{!! Form::text('name', null, ["class"=>"form-control", "required"=>"required"]) !!}
{!! Form::label('email', 'Correo electrónico', ['class'=>'control-label']) !!}
{!! Form::email('email', null, ["class"=>"form-control", "required"=>"required"]) !!}
{!! Form::label('rol_id', 'Tipo de usuario', ['class'=>'control-label']) !!}
{!! Form::select('rol_id', $roles, null, ["class"=>"form-control", "required"=>"required"]) !!}
{!! Form::label('short_bio', 'Biografia', ['class'=>'control-label']) !!}
{!! Form::text('short_bio', null, ["class"=>"form-control", "id"=>"short_bio", "required"=>"required"]) !!}
\ No newline at end of file
@extends('layouts.admin.admin-layout')
@section('content')
<div class='row collapse' id='xxx'>
<div class='col-md-10 offset-1'>
<div class='box'>
<div class='box-header dark'>
<h2>
Nuevo usuario
<span>
<a aria-expanded='false' data-toggle='collapse' href='#xxx' class="btn btn-xs danger">
Cancelar
</a>
</span>
</h2>
</div>
<div class='box-body'>
<div class="row">
<div class="col-md-8 offset-2">
{!! Form::open(['route'=> ['user.store'],"method"=>"POST"]) !!}
@include('user-admin::fields')
{!! Form::label('password', 'Password', ['class'=>'control-label']) !!}
{!! Form::text('password', null, ["class"=>"form-control", "id"=>"password", "required"=>"required"]) !!}
<br>
{!! Form::submit('Registrar', ['class'=>'btn btn-block btn-primary']) !!}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class='col-md-10 offset-1'>
<div class='box'>
<div class='box-header dark'>
<h2>
Listado de usuarios
<span>
<a aria-expanded='false' data-toggle='collapse' href='#xxx' class="btn btn-xs primary">
Agregar usuarios
</a>
</span>
</h2>
</div>
<div class='box-body'>
<table class='table' id="users">
<thead>
<tr>
<th>#</th>
<th>Nombre</th>
<th>Correo</th>
<th>Bio</th>
<th>Tipo</th>
<th>Fecha de creación</th>
<th></th>
</tr>
</thead>
</table>
</div>
<div class='dker p-a text-right'></div>
</div>
</div>
</div>
@endsection
@push('scripts')
<script>
$(function() {
$('#users').DataTable({
processing: true,
serverSide: true,
pageLength: 25,
ajax: '{{ route("user.datatable") }}',
columns: [
{data: 'id', name: 'id'},
{data: 'name', name: 'name'},
{data: 'email', name: 'email'},
{data: 'short_bio', name: 'short_bio'},
{data: 'rol_id', name: 'rol_id'},
{data: 'created_at', name: 'created_at'},
{data: 'details_url', name: 'details_url'},
]
});
});
</script>
@endpush
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment