mardi 1 décembre 2015

MySQL & PHP - How to convert date, time, and timezone when stored separately

In our application, we're currently storing date, time, and timezone separately. The date field is optional, which is why we have everything separated. For the user interface, they will specifically select a date, a time, and then a timezone. Everything is currently stored in UTC and the timezone would be an ID, which references another lookup table.

The way I understand and see it, we can display the date and time the user specified, simply by showing all three of those values without having to adjust anything. If they entered 11-30-15 6:00PM PST, that's what they'll see, formatted however we see fit.

  • Are there any immediate issues anyone can think of doing it this way so far?
  • How should I handle the time conversion? At some point in the system, it needs to understand the actual time. The system time is UTC, but if some work needs to be performed at 11:00AM PST, then it needs to know that. I'm wondering if there is an issue storing the time as UTC, but having them specify a timezone that is different. For example, the time is supposed to be PST, but is stored as UTC.

I am using Laravel with Carbon, just to provide more information. Any feedback would be great!



via Chebli Mohamed

Laravel 5.1 login form

I'm putting together a small web app using Laravel 5.1.

However whenever I submit the login form (1) rather than being redirect( which is set) or some form of error data being returned the same form is displayed again with no errors or useful response to help diagnose why authentication isn't taking place.

Any suggestions would be gratefully accepted.

1

   {!!Form::open(array('method'=>'POST','action'=>'Auth\AuthController@postLogin'))!!}
    <div class="form-group">
    {!!Form::label('Email','Email')!!}
    {!!Form::email('Email',null,['class'=>'form-control'])!!}
    {!!Form::label('Password','Password')!!}
    {!!Form::password('Password',['class'=>'form-control'])!!}
    {!!Form::label('Remember Me', 'Remember Me')!!}
    {!!Form::checkbox('Remember me',null,null,['class'=>'form-control'])!!}
    {!!Form::submit('login',['class'=>'btn btn-primary form-control'])!!}

Route.php

    // ...
    Route::get('auth/login', 'Auth\AuthController@getLogin');

    Route::post('auth/login', 'Auth\AuthController@postLogin');
    Route::get('auth/logout', 'Auth\AuthController@getLogout');

   Route::controllers([
  'password' => 'Auth\PasswordController',
]);



via Chebli Mohamed

Laravel 5.1 - Relationships through two parallel pivot tables

Assume we have four tables; Matrix, Row, Column and Cell.

Matrix
  id

Row
  id
  matrix_id
  label

Column
  id
  matrix_id
  label

Cell
  id
  row_id
  column_id
  text

The relationships thus look something like

    Matrix
   /      \
  Row   Column
   \      /
     Cell

Can the relationship between Matrix and Cell through Row and Column be represented somehow in Laravel 5.1? So that I could for example have a cells() method on Matrix that returns a Relation to the cells it has through Row and Column.



via Chebli Mohamed

Dynamic Pages routes in Laravel

The question seems realy simple, but I can't figure it out... How do you achieve slug-based dynamic pages with categories in Laravel 5.1?

Something like http://ift.tt/1Nocon1

I know that Route::get('/{slug}') gives the "slug" as identifier, but the problem is that the page could be situated in http://ift.tt/1Suu6W4, so if set the route to something like Route::get('/{category}/{subcategory}/{page}') it will not work for the second example.

I was thinking about making 3 routes like

Route::get('/{category}/{subcategory}/{page}')
Route::get('/{category}/{page}')
Route::get('/{page}')

And then the controller to receive ($category = null, $subcategory = null, $page = null) And in the controller something like

if (!$page)
    $page = $subcategory;

if (!$page)
    $page = $category;

Is there another, cleaner way to achieve this? Because here we have only 2 category routes, but there could be 3, 5 or more?



via Chebli Mohamed

Join in Laravel 5.1

I'm new to Laravel and I'm still working on my Project using this Framework. In my project, I use an SQL JOIN but I don't know how to retrieve/fetch data on the joined table. Can anybody help me on this one? I really appreciate your help. Thanks! Here is a simple example!

$users = DB::table('users')
        ->join('contacts', 'users.id', '=', 'contacts.user_id')
        ->join('orders', 'users.id', '=', 'orders.user_id')
        ->select('users.*', 'contacts.phone', 'orders.price')
        ->get();



via Chebli Mohamed

Create data to be outputted in a view?

In my view I output data from my database in the view via:

{{ $data->id }}

In one particular view I need do not get the data from a database but need to keep the view the same and manually set the id.

I've tried setting the id in my controller like:

$data['id'=>1];

But this fails to output in the view with:

{{ $data->id }}

Where am I going wrong?



via Chebli Mohamed

PHP-Laravel5 except csrf from another website

I've tried to exclude requests from another localhost server (http://localhost:8080/order/placeorder) to another one localhost server (http://localhost:8000) I don't want to disable all csrf protection by removing \App\Http\Middleware\VerifyCsrfToken::class, in Illuminate\Foundation\Http\Kernel.php

I've tried to modify app/Http/Middleware/VerifyCsrfToken.php

protected $except = [
    'http://localhost:8080/*',
    'http://localhost:8080',
    '/order/placeorder/*',
    'http://localhost:8080/order/placeorder'
];

and I also tried this way

private $openRoutes = [
    'http://localhost:8080/*',
    'http://localhost:8080',
    '/order/placeorder/*',
    'http://localhost:8080/order/placeorder'
];

public function handle($request, Closure $next)
{
    //add this condition
    foreach($this->openRoutes as $route) {

        if ($request->is($route)) {
            return $next($request);
        }
    }

    return parent::handle($request, $next);
}

But I still got this error --->> TokenMismatchException in VerifyCsrfToken.php Can anyone suggest me what should I do and what I've done wrong? Thank you



via Chebli Mohamed