Skip to content

Commit

Permalink
fix the batches cannot created without design and the users list
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzahjamad committed Oct 19, 2017
1 parent 4e17037 commit f7f3c6a
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 6 deletions.
16 changes: 11 additions & 5 deletions app/Http/Controllers/BatchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ public function store(Request $request)
'name'=>'required',
]);

$imageName = str_random(10).date('Y-m-d'). '.' .$request->file('design')->getClientOriginalExtension();
$path = 'storage/designs/';
$full_path = $path.$imageName;

$request->file('design')->move(base_path() . '/public/'.$path, $imageName);

$batch = new Batch;
$batch->name = $request->name;
$batch->design = $full_path;


if($request->file('design')){
$imageName = str_random(10).date('Y-m-d'). '.' .$request->file('design')->getClientOriginalExtension();
$path = 'storage/designs/';
$full_path = $path.$imageName;
$request->file('design')->move(base_path() . '/public/'.$path, $imageName);

$batch->design = $full_path;
}

$batch->save();


Expand Down
29 changes: 29 additions & 0 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

class UserController extends Controller
{
public function __construct()
{
$this->middleware(['auth', 'auth.admin']);
}

public function index()
{
$users = User::paginate(5);
return view('user-all', compact('users'));
}

public function updateAccess($id)
{
$user = User::find($id);
$user->have_access = $user->have_access ? false : true;
$user->save();

return back();
}
}
5 changes: 4 additions & 1 deletion resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
@endif

@if(Auth::user()->have_access)
<a href="/batches">View all batches</a>
<ul>
<li><a href="/batches">View all batches</a></li>
<li><a href="/users">View all users</a></li>
</ul>
@else
<div class="alert alert-info" role="alert">Your account are still not active, please ask admin to activate your account.</div>
@endif
Expand Down
5 changes: 5 additions & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@

<ul class="dropdown-menu" role="menu">
<li>
@if(Auth::user()->have_access)
<a href="/users">
All Users
</a>
<a href="/batches">
All Batches
</a>
@endif
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Expand Down
59 changes: 59 additions & 0 deletions resources/views/user-all.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@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">All Users</div>

<div class="panel-body table-responsive">
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif

<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Access</th>
<th>Created At</th>
<th>Updated At</th>
<th>Action</th>
</tr>
</thead>
<tbody>

@foreach($users as $user)
<tr>
<td>#{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
<td>{{$user->have_access ? 'Yes' : 'No'}}</td>
<td>{{$user->created_at}}</td>
<td>{{$user->updated_at}}</td>
<td>
{!! Form::open(['url' => "/users/{$user->id}/update-access"]) !!}
<button type="submit" class="btn btn-default">
<span class="glyphicon {{ $user->have_access ? 'glyphicon-remove' : 'glyphicon-ok'}}" aria-hidden="true"></span>
</button>

{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
{{ $users->links() }}
<hr>
</div>
</div>
</div>
</div>
</div>

@endsection
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

Route::get('/home', 'HomeController@index')->name('home');

Route::get('/users', 'UserController@index')->name('users');
Route::post('/users/{id}/update-access', 'UserController@updateAccess')->name('users.access');

Route::resource('/batches/{bid}/recipients', 'RecipientController', ['only' => [
'create', 'edit', 'store', 'update', 'destroy',
]]);
Expand Down

0 comments on commit f7f3c6a

Please sign in to comment.