In laravel configuration variables can be accessed like this
Config::get('xxx')
By default it returns the configuration values for the current environment. How do you get configuration data for other environments?
In laravel configuration variables can be accessed like this
Config::get('xxx')
By default it returns the configuration values for the current environment. How do you get configuration data for other environments?
A call to Config::get()
will already get you information of your current environment, if you are in dev it will be dev, if you are in production it will be the production data.
If you need to get a configuration information about another environment you can do by:
return Config::get('environment/config.name');
Example:
return Config::get('testing/cache.driver');
If you need to get things from your production environment while being in any other one, I'm afraid you'll have to create a 'production' folder inside your config folder and put those things there:
app/config/production/database.php
Add to that particular file only what you need to read outside from your environment:
'default' => 'postgresql',
And then you'll have access to it:
return Config::get('production/database.default');
spring,properties,configuration,spring-boot
You need to add setters and getters to ServerConfiguration You don't need to annotate class with nested properties with @ConfigurationProperties There is a mismatch in names between ServerConfiguration.description and property my.servers[X].server.name=test ...
php,arrays,sorting,datetime,laravel
You can use Laravel's collection groupBy method to group your records for your needs. $records = YourModel::all(); $byHour = $records->groupBy(function($record) { return $record->your_date_field->hour; }); $byDay = $records->groupBy(function($record) { return $record->your_date_field->dayOfWeek; }); Remember that this code to work, you have to define your date field in the $dates Model array, in...
Something like this may work... the idea is to add an additional select which is 0 or 1 depending on if the date is today. Then you can order by that column first, then the actual date second. public function scopeRestaurantsWithMenusToday($query, $city_uri){ return $query->where('city_uri', '=', $city_uri)->with([ 'restaurants', 'restaurants.menusToday' => function($query)...
php,laravel,timestamp,eloquent
As mentioned in comments, if the model did not change the timestamps wont be updated. However if you need to update them, or want to check if everything is working fine use $model->touch() - more here
I had similar problem. I modified the render function in app\Exceptions\Handler.php to public function render($request, Exception $e) { if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) { return response()->view('index'); } return parent::render($request, $e); } and created an index.blade.php view in resources\views folder, which was like <?php include public_path().'/views/index.html'; and it contains all the angular...
git,laravel,repository,laravel-5,composer-php
Having a look at your repository in https://github.com/Yunishawash/api-guard it looks like it doesn't have a branch called dev-fullauth. Instead there is a branch dev-bugfix. But you must not name your branch including the dev- prefix. Rename your branch at github from dev-bugfix to bugfix and then your require section would...
You want to look into polymorphic relations to solve this. You want to be able to comment on Posts and Comments. What I have done is set up a commentable trait and have the models I want to add comments to use it. This way if you ever want to...
postgresql,laravel,laravel-5,laravel-migrations
Laravel use constraint on character varying for enum. Assuming there is a table mytable with an enum column status, we have to drop the constraint (named tablename_columnname_check) then add it in a migration like this: DB::transaction(function () { DB::statement('ALTER TABLE mytable DROP CONSTRAINT mytable_status_check;'); DB::statement('ALTER TABLE mytable ADD CONSTRAINT mytable_status_check...
php,laravel,laravel-5,homestead
When running the queue worker as a daemon, you must tell the worker to restart after a code change. Since daemon queue workers are long-lived processes, they will not pick up changes in your code without being restarted. So, the simplest way to deploy an application using daemon queue workers...
php,mysql,laravel,eloquent,laravel-5
As far as syncing/attaching you can use this sytanx $user->roles()->sync([1, 2, 3]); As given in Laravel Docs You can do the both checks in the condition of IF and assign in case of true, thats how your controller will look like finally. public function share(Request $request) { $userId = $request->input('user_id');...
php,sql-server,laravel,eloquent
It would be a good idea to use whereHas() on the Post model to eager load the tags and get only the Posts which have at least one of those tags. $posts = Post::whereHas('tags', function($q) use ($tags) { $q->whereIn('id', $tags); })->get(); Here, $tags would just be an array of tag...
Until Predis' zAdd method is updated to support the changes in Redis v3.0.2, your best bet is to explore the wonderful world of RawCommand: https://github.com/nrk/predis/blob/master/src/Command/RawCommand.php It should let you construct your own commands, including the ZADD NX ... variant....
What you are trying to do is not possible in the storage directory but possible only in public directory, also exposing the path or URL to your laravel storage directory creates some vulnerability and its bad practice However there is a way to workaround it: First, you need an Image...
{{ $var or 'No Phone' }} === {{ isset($var)? $var : 'No Phone' }} Because $user->phone is defined you should use this: {{ $user->phone? $user->phone : 'No Phone' }} Or, you can go nice Laravel way and create your own directive for Blade templates and use it like this: @var($user->phone,...
The purpose isn't for re-direction in your routing file. Instead, with the example route you provided, Laravel will allow you to reference said route by using: $url = route('profile'); Rather then having to build the url manually in your code. So, in short: the difference is the first thing is...
php,laravel,interface,namespaces
In my recent laravel 5 project, I'm used to prepare my logics as Repository method. So here's my current directory structure. For example we have 'Car'. So first I just create directory call it libs under app directory and loaded it to composer.json "autoload": { "classmap": [ "database", "app/libs" //this...
rest,laravel,polymorphism,eloquent
You might be almost there. Your getAvatarAttribute() is way too complicated, indeed. You could try to do something like: /** we hide the relation from the json */ protected $hidden = ['avatar']; /** we append the url of the avatar to the json */ protected $appends = ['avatar_url']; /** *...
visual-studio-2013,configuration,typescript,publishing
However while publishing my project, it still generates js and js.map file foreach .ts files. You probably have different config for debug and release. Make them the same....
laravel,vagrant,virtual-machine,homestead
Are you using cygwin? You should run the commands inside the Homestead folder which is created after you do homestead init. Then you do the configuration or mapping of folders in your Homestead.yaml. it is located in you home directory. in my case in created a .homestead folder. I'm using...
php,laravel,redirect,pagination,laravel-5
If you look in your app/public/.htaccess file you will see this line: # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] By removing it you will disable trailing slash redirect....
javascript,php,jquery,laravel,laravel-5
I solved it by doing this HTML {!! Form::model($user, array('route' => array('user.update_profile_picture', $user->id ),'method' => 'PUT')) !!} <a class="pmop-edit" > <span id="file-upload" > <i class="md md-camera-alt"></i> <span class="hidden-xs">Update Profile Picture</span> </span> <div style='height: 0px;width: 0px; overflow:hidden;'> <input id="upfile" type="file" value="upload" onchange="sub(this)" /> </div> </a> {!! Form::hidden('$id', $user->id)!!} {!!...
Eventually you can install php DOM extension. Certain Linux distributions do not have this extension included in the minimum PHP package. It can usually be found in one of the "optional" php-* packages. On CentOS you should be able to just run yum install php-dom or yum install php-xml. That...
php,laravel,laravel-5,laravel-routing
Your <a> link will trigger a GET request, not a PATCH request. You can use JS to have it trigger a PATCH request, or use a <button> or <input type="submit"> to issue one.
laravel,nginx,vagrant,virtualbox,homestead
Easiest way to achieve this is editing scripts/serve.sh file, which contains server block template in block variable.
jquery,html,css,twitter-bootstrap,laravel
What the problem is is that you are using the link tag where you actually should be using the script tag: <link rel="text/javascript" href="{{ URL::asset('assets/js/jquery.js') }}" /> <link rel="text/javascript" href="{{ URL::asset('assets/js/bootstrap.min.js') }}" /> Javascript should be in a script tag for it to load into your page: <script type="text/javascript" src="{{...
The relation is a hasMany and will therefor return a collection set, not one "echoable" thing: $mensajes = Messageuser::find(1)->conversaciones()->get(); $mensajes2 = Messageuser::find(4)->conversaciones()->get(); \dd($mensajes, $mensajes2); This will return two Collection objects dumped. Please also note that you can use: $mensajes = Messageuser::find(1)->conversaciones; To get the same return set. Now you want...
The problem was in your homestead.yaml file. folders: - map: C:\Users\Lisa\Documents\Homestead\larapipeline to: /home/vagrant/Code/larapipelin - map: C:\Users\Lisa\Documents\Homestead\tinkertower to: /home/vagrant/Code/tinkertower sites: - map: homestead.app to: /home/vagrant/Code/larapipeline/public - map: tinkertower.app to: /home/vagrant/code/tinkertower/public Don't forget to edit your hosts file. Now run vagrant up --provision, or vagrant reload --provision. Edit: Fixed case sensitivity issue...
Do you mean you want to limit the number of characters in a string? This can be done in laravel by a string helper: $value = str_limit('The PHP framework for web artisans.', 7); So in your example: <p>{{ str_limit($subasta->descripcion, 20) }}</p> ...
php,laravel,eloquent,laravel-5
I think what will help you achieve this behavior is the lists() method. Try something like $user_genres = auth()->user()->genres()->lists('name','id'); If you are using Forms & HTML package you can just do {!! Form::select('genres',$user_genres,null) !!} And here is your dropdown More info here (scroll down to "Retrieving A List Of Column...
When creating a foreign key constraint, you can also decide what should happen with the constraints. For instance, if you want to delete all articles when a category is deleted (as I guess is your question): Schema::table('articulos', function($table) { $table->foreign('categoria_id')->references('id')->on('categorias')->onDelete('cascade'); $table->foreign('creador_id')->references('id')->on('users'); }); Also see documentation. The cascade identifies to the...
In your admin template you set the goto url as sessions.store which hits SessionsController::store in that method you have a debug function dd() which is throwing that string. It get's called because auth::attempt() returns false as by your own code: if($attempt) return Redirect::intended('/'); So the behavior is exactly doing what...
Try as below : <?php $properties = array('office', 'retail'); ?> @foreach ($properties as $property) {{{ $property }}} @endforeach ...
When you did the git reset --soft HEAD~1, you "moved backwards" a commit, while keeping your working directory and index the same. So when you committed, the files were changed as if you had done the merge, without doing an actual merge; i.e., your commit had only one parent. I'm...
php,laravel,checkbox,laravel-5
Have you put the field 'optin' in the $fillable array within the model? Otherwise you cant create a User with 'optin' using the static create method. //File: User.php protected $fillable = ['optin']; ...
Actually, you should reserve in config/app.php file. Then, you can add In the Service Providers array : 'Menu\MenuServiceProvider', In the aliases array : 'Menu' => 'Menu\Menu', Finally, you need to run the following command; php artisan dump-autoload I assume that you already added this package in composer.json Sorry, I didn't...
php,class,oop,laravel,laravel-5
That's simple php stuff. Set the attribute as static and access it with ::. class LanguageMiddleware { public static $languages = ['en','es','fr','de','pt','pl','zh','ja']; } @foreach (App\Http\Middleware\LanguageMiddleware::$languages as $lang) ... @endforeach You should not have that in a middleware though. You'd better add a configuration (i.e in /config/app.php) with that array, and...
You can only send serializable entities to the queue. This includes Eloquent models etc. But not the PDF view instance. So you will probably need to do the following: Mail::queue('emails.factuur', array('factuur' => $factuur), function($message) { $pdf = PDF::loadView('layouts.factuur', array('factuur' => $factuur)); $message->to(Input::get('email'), Input::get('naam'))->subject('Onderwerp'); $message->attach($pdf->output()); }); ...
You are trying to route something within a route definition itself. That is not how it works. There are a few ways you could do what you want to achieve. There are pros/cons to each - but they would all work. Generally the best way is to use some Auth...
laravel,laravel-5,laravel-validation
1. Theoretically there is no difference between Controller validation and Validation using FormRequest. Normally you should use FormRequest. This will keep your controller clean and Minimal. But some time it is sensible to use Validator within controller, e.g you know there is going to be just one field to validate,...
You can do: Route::getCurrentRoute()->getParameter('id') See Illuminate\Routing\Route.php /** * Get a given parameter from the route. * * @param string $name * @param mixed $default * @return string|object */ public function getParameter($name, $default = null) { return $this->parameter($name, $default); } ...
php,laravel,exception-handling,laravel-5
You could handle this in Laravel app/Exceptions/Hnadler.php NB: I have looked in the option of using DOMException handler which is available in PHP, however the error message you are getting in not really and exception by an I/O Warning. This what PHP native DomException looks like: /** * DOM operations...
Closures work just like a regular function. You need to inject your outer scope variables into function's scope. Mail::send('invoices.mail', array($pinvoices,$unpinvoices), function($message) use ($email) { $message->to($email , 'Name')->subject('your invoices '); }); ...
php,sql,laravel,eloquent,belongs-to
Well, this error occurred because I had '.' in place of '->'. I couldn't figure out why it was always throwing the exact same error regardless if I did $this.belongsTo('App\User'); or $this.hasMany('App\User'); or even $this.thecakeisalie('App\User'); until I sat staring at the text between my many models yet again. Then, lo...
As per your requirement, I blieve you have to update your relation to Polymorphic Relations. and than to access other attributes try one of them method. $user->roles()->attach(1, ['expires' => $expires]); $user->roles()->sync([1 => ['expires' => true]]); User::find(1)->roles()->save($role, ['expires' => $expires]); If you still facing some dificulties to handle that requirement let...
authentication,laravel,constructor
You can use Auth::user() in the whole application. It doesn't matter where you are. But, in response to your question, you can use the 'Controller' class present in your controllers folder. Add a constructor there and make the reference to the user ID. <?php namespace App\Http\Controllers; use Illuminate\Foundation\Bus\DispatchesCommands; use Illuminate\Routing\Controller...
php,events,laravel,domain-driven-design,dispatcher
Lately I favor returning events from domain methods and handling those in the application service layer. Since the application service layer is where you bring together all kinds of infrastructure further processing of the returned events, such as dispatching, can be handled in the application service layer. In this way...
sql-server,configuration,session-state,asp.net-5,asp.net-mvc-6
Support for SQL Server Session State is currently in development. So your best options for now are using In-Memory session(which has the issue which you mentioned about state not persisted for multiple servers behind load balancer kind of scenarios). However you could try using Redis cache(ASP.NET 5 Session implementation is...
php,validation,laravel,laravel-4,laravel-5
You are getting Forbidden Error because authorize() method of form request is returning false: The issue is this: $clinicId = $this->route('postUpdateAddress'); To access a route parameter value in Form Requests you could do this: $clinicId = \Route::input('id'); //to get the value of {id} so authorize() should look like this: public...
jquery,ajax,json,laravel,laravel-5
Use this as your code: e.preventDefault(); var mydata = new FormData($('#my_form')[0]); $.ajax({ type: 'POST', cache: false, dataType: 'JSON', url: 'tasks', data: mydata, processData: false, contentType: flase success: function(data) { console.log(data); }, }); Note that this doesn't work on some older browsers such as IE 9 or older so you might...
My suspicion is that the third parameter is expecting a route name, not a URL. Your routes.php route is not a named route. Route::get('done', ['as' => 'done', 'uses' => '[email protected]']); ...