mardi 2 août 2016

for each loop in controller adding data to object

This is loop inside my controller:

 foreach(Classes::all() as $classes){
        $classes->student;
    }
    return view('configuration.configuration')->with('classes', $classes);

My question is how to make an object that will fill itself in each passing, so that I can pass that object to view.



via Chebli Mohamed

lundi 1 août 2016

laravel relationship between user and user_info tables

i'm newbie on laravel 5.1 so i have an easy problem.

i have user table and user_info table. if i create a user, i want to create another record for user_info table and if i get user then i want to get user_info record but i don't do this.

codes are below.

<?php
namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{

    protected $fillable = [
        'name', 'email', 'password',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];

    public function profile()
    {
        return $this->hasOne('Http\Models\userInfo');
    }
}

this is userInfo class

<?php

namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;

class userInfo extends Model
{
    protected $table = 'user_info';
}

this is welcome page

@extends('master')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading">Welcome</div>

                <div class="panel-body">
                    <pre></pre>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

i got this error

FatalErrorException in Model.php line 740:
Class 'Http\Models\userInfo' not found

where am I doing wrong?



via Chebli Mohamed

All Laravel routes gives 404 on nginx subdirectory

I have problem with nginx configuration. I wanna have Laravel app in subdirectory, exactly domain.com/alfa. At domain.com is another app. And now all Laravel routes gives 404 on nginx subdirectory. Could someone help you find an error?

My paths:

  • /var/www/ <-- it's for domain.com
  • /var/www/alfa_path <-- it's for domain.com/alfa

It's my nginx configuration:

server
{
        listen 80;
        server_name domain.com;

        root /var/www;
        index index.php index.html index.htm;

        location / {
        }

        location /alfa {
                root /var/www/alfa_path/public;
                index index.php index.html index.htm;
                try_files $uri $uri/ /alfa_path/public/index.php?$query_string;
        }

        location ~ .php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/www.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
        }

        location /phpmyadmin {
                root /usr/share/;
                index index.php index.html index.htm;
                location ~ ^/phpmyadmin/(.+\.php)$ {
                        try_files $uri =404;
                        root /usr/share/;
                        fastcgi_pass unix:/var/run/www.sock;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include /etc/nginx/fastcgi_params;
                }
                location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                        root /usr/share/;
                }
        }

        location /phpMyAdmin {
                rewrite ^/* /phpmyadmin last;
        }
}

laravel 404



via Chebli Mohamed

How can I return a random asset from specific folder?

I need to create a route where a random image or video is returned from a specific directory, how can I achieve this?



via Chebli Mohamed

Auth::once($credentials) always false

I have one route, this route call my controller. Inside this controller I have :

  $user = Auth::loginUsingId(1); // This data get from a form
  $mail = $user->email;
  $pass = $user->password;     

  $credentials = [
   'email'    => $mail,
   'password' => $pass,
  ];

  if (Auth::once($credentials)) {
      return Auth::user()->id;
  }

  return \App\Login::where('email', '=', $mail)->where('password', '=',$pass)->first(); // I can see my user, with his email and password. It is a exmplante, later when this is working I will put false

My model is Login.php instead of User.php

class Login extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract {

use Authenticatable, Authorizable, CanResetPassword;

protected $table = 'logins';
protected $fillable = ['email','password'];
protected $hidden = ['created_at','updated_at_at'];

public function setPasswordAttribute($password)
{
    $this->attributes['password'] = bcrypt($password);
}

And I change the file config/auth.php

'driver' => 'eloquent',
'model' => \App\Login::class,
'table' => 'logins',

'password' => [
    'email'  => 'emails.password',
    'table'  => 'password_resets',
    'expire' => 60,
],

I try use the Auth::attempt() but I have the same problem, I do not understand because I can connect my database, I config the new model in config/auth ...



via Chebli Mohamed

Laravel 5.2 TokenMisMatchException on Production Server

I am encountering TokenMismatchException on my Production Server, but the application working fine on local Xampp server and another hosting. It our in house server, so we cannot changed it. We have to use it, but we did not understand where is the issue.

Please friends help me, did i need to change anything in server like plugin, extensions or anything else, Please let me know. Here is screen shot below:

Error on production when submitting login blank and geeting token mismatchexception

This on my personal hosting and the same is working fine here.

Above sceenshot is from Production and one of hosting provider. On production server laravel application giving tokenmismatchexception whereas same application working fine on another hosting provider. We did not understand why this is happening. Please suggest us what to do.



via Chebli Mohamed

How to delete duplicated row in Laravel 5.2

I try to delete duplicated row in my code with :

$post = new posts();
$post->raw('DELETE b1 FROM baroot b1,baroot b2 WHERE b1.post_id = b2.post_id AND b1.id > b2.id');

and my model code is :

class posts extends Model
{
    protected $table = 'baroot';

    protected $fillable = [
        'post_id', 'title', 'modify',
    ];
}

I try to delete duplicated with :

$post = new posts();
$post->raw('DELETE b1 FROM posts b1,posts b2 WHERE b1.post_id = b2.post_id AND b1.id > b2.id');

but any duplicated rows not deleted, I know the sql query is correct but don't work with my laravel code



via Chebli Mohamed