samedi 27 août 2016

How do you correctly implement Doctrine ACL Organisations in Laravel 5.3?

TL;DR

Does anyone have a solid example of how to implement Organisations using the Doctrine Laravel package as I feel like the docs don't say enough (or maybe i'm just after too much hand holding)


I'm trying to create and attach my user entity to an another entity that implements organisations in Doctrine Laravel but I'm completely stuck at what to do next from reading the documentation...

Currently my set up is like this:

<?php

namespace App\Entities;

use Doctrine\ORM\Mapping as ORM;
use LaravelDoctrine\ACL\Contracts\Organisation;
use LaravelDoctrine\ACL\Mappings as ACL;

/**
 * @ORM\Entity
 * @ORM\Entity(repositoryClass="App\Repositories\ShelterRepository")
 * @ORM\Table(name="shelters")
 */
class Shelter implements Organisation
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $name = null;

    /**
     * @ORM\Column(type="string", unique=true, nullable=false)
     */
    protected $handle;


    //... Getters and setters
}

And my user entity:

<?php

namespace App\Entities;

use Doctrine\ORM\Mapping as ORM;
use LaravelDoctrine\ORM\Auth\Authenticatable;
use LaravelDoctrine\Extensions\Timestamps\Timestamps;
use Illuminate\Auth\Passwords\CanResetPassword;
use LaravelDoctrine\ACL\Mappings as ACL;
use LaravelDoctrine\ACL\Contracts\BelongsToOrganisations;

/**
 * @ORM\Entity(repositoryClass="App\Repositories\UserRepository")
 * @ORM\Table(name="users")
 * @ORM\HasLifecycleCallbacks()
 */
class User implements \Illuminate\Contracts\Auth\Authenticatable, BelongsToOrganisations
{
    use Authenticatable;
    use Timestamps;
    use CanResetPassword;

    /**
     * @ACL\BelongsToOrganisations
     * @var Shelter[]
     */
    protected $organisations;

    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    protected $id;

    /**
     * @return Organisation[]
     */
    public function getOrganisations()
    {
        return $this->organisations;
    }

    //... Other properties and getters/setters

}

When I then run doctrine:schema:update no new columns get added nor any pivots or anything to suggest a relation between Shelter and Userand if I get the first user and try $user->belongsToOrganisation($shelter) I get:

Call to undefined method App\Entities\User::belongsToOrganisation()

I'm not really sure what to do next and the docs kinda stop at this point, am I meant to implement the rest myself? It feels like @ACL\BelongsToOrganisations on the User entity should be doing something but nothing happens so I'm not sure how I should go about adding relations etc.

Anyone with any public code where they've implemented this or any pointers would be amazing, my searches in google/youtube/github have turned up fruitless.

Thank you!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bI8fjq
via IFTTT

config nginx(v 1.10) for laravel (v 5)with php 5.6

The config for nginx here:

user nginx;
worker_processes  4;
events {
worker_connections  1024;
}

http {
include       mime.types;
default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  65;
include /usr/local/nginx/conf/virtual/*.conf;
}

the virtual.conf in virtual file:

server {  
listen 80 default_server;

root /www/laravel/public;
index index.html index.htm index.php;

server_name laravel.rexchen.cn;

charset utf-8;

location / {
    try_files \$uri \$uri/ /index.php?\$query_string;
}

 # Note this will work with "hack" files as well as php files!
 location ~ \.(hh|php)$ {  
      fastcgi_keep_conn on;
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include        fastcgi_params;

}

# Deny .htaccess file access
location ~ /\.ht {
    deny all;
}

}

the chrome report that 500 error:enter image description here

so how fix this



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bGHWZp
via IFTTT

How to setup mysql database in laravel

I am new laravel programmer, and I have simple question about setting up database.

Assume that I create all required migrations, models, and eloquent relationships, also configure mysql database in laravel, now in this point, is laravel will create all mysql tables required in server's DB according to migrations, models, and eloquent that I created before? In other words, do I need to create tables in mysql server as scratch developer do?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bGFWjR
via IFTTT

laravel 5 query builder restrict

well i am stuck in this scenario
there is 3 tables candidate table,position table and recruitment form table. Candidate-id and position-id is a foreign key in recruitment form table when candidate apply for a position which he already applied he can't apply for that post again i tried something like this but not working . If there some error please solve it or recommend some other method to achieve this thank you.

$check = DB::table('recruitmentform')->select('positionid')->where('candidateid',$cid)->get();

    for ($i = 0; $i < count($check); $i++) {
        if ($check[$i] == $pid) {
            return redirect('/');
        }
    }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2by6nX8
via IFTTT

Http callback is never called, Vue Laravel

Got this in a Vue component (Users.vue). The fetchUsers-function is called but the callback-function is NEVER called. I've tried to attach .error()-func but I get an error of this.$http.get(...).error is not a function.

<template>
    <div class="panel panel-default">
        <div class="panel-heading">Användare</div>

        <div class="panel-body">
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Name</th>
                        <th>Email</th>
                    </tr>   
                </thead>
                <tbody>
                    <tr v-for="user in users">
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</template>

<script>
    export default {

        name: "Users",

        ready() {
            console.log('Component ready.')

            this.fetchUsers();
        },

        methods: {
            fetchUsers: function() {
                console.log("Fetching users...");

                this.$http.get('/api/user', (data) => {
                    this.$set("users", data);
                });
            }
        }
    }
</script>

I use Laravel's framework that ships with Vue.js. Don't know how it all works but I get the component showing up in the web browser and I get output in the console from this code.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bYlmsZ
via IFTTT

Laravel 5: Update record without changing current date/time value of updated_at field

In my Laravel 5 project, I would like to increase the number of views when a visitor come/refresh on the product page like:

$rds = Product::whereId($id)->first();
$rds->hits++;
$rds->save();

The problem is that the field: updated_at automatically update, which is not what I want at all because I would like to change only field: hits, not update_at field.

If I set $rds->updated_at = false; the field is updated to be '0000-00-00 00:00:0'.

Could you advise how to prevent updated_at field from automatically changing for only certain function?

Best Regards, Naren



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bsyZ23
via IFTTT

Laravel 5 - How to seed table automatically after deploying an app?

I have a certain data that must be in table in order for my app to work, otherwise i get an error message.

For example if YOU or anyone else pulled my app from github and if you run php artisan migrate and then try to test the app you would get an error: data doesn't exist or something like that. and it's because there is no data in table.

So ideal solution would be after running:

 php artisan migrate

that you also get this needed data in that table.

This should be done somehow with the seeder but i don't know how. Can anyone help and give me an example?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bHBxi0
via IFTTT