Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have tried the following code but is show some error. Please tel me whats wrong with the following code?
<?php
public $PreviousId;
public $HasNextcandidate= $this->HasCandidateValue();
public function HasCandidateValue()
{
return ($PreviousId!=NULL);
}
?>
You can't assign values to member variables using expressions including function/method calls.
So public $HasNextcandidate= $this->HasCandidateValue(); is not valid. You need to do something like:
public $HasNextcandidate= '';
and then in your constructor do:
$this->HasNextcandidate = $this->HasCandidateValue();
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
I want auth()->user() for do some operation in handler.php file that inside App\Exceptions.
I have done research on it but not find anything.
This is probably because user is still not authenticated before it gets to the handler.
This is desired behavior, but there are some workarounds as stated in this answer here: https://stackoverflow.com/a/41400225/7770919
What #geertjanknapen is referring to is this: https://laravel.com/docs/9.x/errors#rendering-exceptions
You can use auth()->user() in render methods for any exceptions.
Such as:
use App\Exceptions\YourCustomException;
/**
* Register the exception handling callbacks for the application.
*
* #return void
*/
public function register()
{
$this->renderable(function (YourCustomException $e, $request) {
$authenticatedUser = auth()->user();
return response()->view('errors.invalid-order', [], 500)->with('user', $authenticatedUser);
});
}
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed last month.
Improve this question
I have a single form.blade.php that I use to create and modify data. In that form, sometimes I have to display additional fields only in the editing state, while in the creation state they should be hidden.
I tried to define variable $mode with values edit and create in each method and it works ok. From a developer's point of view this seems like a bad solution and I wanted to consult with you on how I could do it in a better way
What i do in controller
public function edit($id)
{
$tag = Tag::find($id);
$mode = 'edit';
return view('tag.edit', compact('tag', 'mode'));
}
public function create()
{
$tag = new Tag();
$mode = 'create';
return view('tag.create', compact('tag', 'mode'));
}
And than in form.blade
#if($mode == 'edit')
....
#else
....
#endif
Do you think there is a better way to do this?
Since the create and edit mode are separate, you can send the mode right when you include the form blade
tag.edit.blade.php
#include('tag.form', ['mode' => 'edit'])
tag.create.blade.php
#include('tag.form', ['mode' => 'create'])
So you dont have to specify it in the controller.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have an array in my command and I want to return the array to a controller where I call the command. This is what I want.
Command :
return $array;
Controller :
$array = Artisan::call('command');
I have also tried this:
Artisan::call('command');
$array = Artisan::output();
But they both don't work. Please help?
You can't get the result of your command back in your controller, (you will only get the "text" from it)
Instead if you want directly a php array, try to export your command's code in a helper function (or in the model you are using in your command), then call it from your controller and your command.
If you can't do that, try this in your handle() function:
$this->line($array->toJson());
then in your controller :
Artisan::call('command');
$json = Artisan::output();
$array = json_decode($json);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to pass a variable from one function to another and displaying via a shortcode on the front end. This is my code
function user_last_logout(){
global $userr;
$userr = 'hi';
}
function get_logout_time(){
global $userr;
echo $userr;
}
add_shortcode('lastlogn','get_logout_time');
You can make the return of the function be the variable that you want, and then just call it inside the other function. Like so:
function user_last_logout()
{
return 'hi';
}
function get_logout_time()
{
echo user_last_logout();
}
add_shortcode('lastlogn','get_logout_time');
Is this what you are looking for?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I got the idea down, and to be so simple, I think it may be impractical, and so I would comment on the pros (if any) and cons of such a system.
The intention was to develop a simple but functional system permissions.
The problem I could see is that if you want to protect a particular function, you have to suddenly rename it to have the conf_ prefix.
I would write a proxy around a class that inspects the doc blocks when a method is invoked. Just an idea:
class ArticlesProxy
{
private $backend;
public function __construct(articles $backend)
{
$this->backend = $backend;
}
public function __call($fn, $args)
{
$rm = new ReflectionMethod($this->backend, $fn);
if (strpos($rm->getDocComment(), 'protected') !== false) {
// this method is protected by whatever
}
// perform the proxy call
return $rm->invokeArgs($args);
}
}
$proxy = new ArticlesProxy(new articles());
$proxy->create(1, 2, 3);