I am looking for a way to put logs in Laravel's controller function.
Where Should I put Log functions? Where Can I find the log?
There are any logs in {Project_name}/storage/logs/laravel.log
I would like to put a logging to check if the request values are all correct.
the setting of .env seems to be APP_DEBUG=true
namespace App\Http\Controllers;
use App\Article;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class StackOvefFloeController extends Controller
{
public function store(ScheduleRequest $request)
{
$schedules = DB::table('schedules')->get();
$request->date;
$request->hours;
//Where Should I put Log functions? Where Can I find the log?
Log::info('start hpirs'. $request->hours);
dd($request->start_hours);
error_log('start hpirs'. $request->start_hours);
return view('debug', ['schedules' => $schedules]);
}
<div class = "test">
<form method="POST" action="{{ route('debug.store') }}">
#csrf
<input type="checkbox" class="date"" name="available_date" value="2015-05-22">
<input class="checkbox" type="checkbox" name="hours" value="8">8
<button type ="submit">SEND</button></form>
</div>
this way correct : Log::info('message');
you can set log file from .env file every day set with this code : APP_LOG=daily
Related
I am using laravel for my whois domain search. But when i use exec command in my controller, there is no output
My controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
class SorgulaController extends Controller
{
//
//
function sorgula (Request $req)
{
$domain = $req->get('domain');
return view('results', compact( 'domain' , ));
}
}
?>
My form blade
<form action="/tr/sonuc" method="post">,
#csrf
<div class="form-group">
<input type="text" name="domain"
class="form-control form-control-lg" value=""
placeholder="" required>
</div>
<br>
<button type="submit" class="btn btn-outline-dark d-grid gap-2 col-3 mx-auto">Sorgula</button>
<br>
<p class="text-center"> <a class="text-primary" href="https://domaintelekom.com/login">oturum açın.</a></p>
</form>
My result blade
<?php
exec("whois $domain" , $data);
echo "<pre>";
print_r($data);
echo "</pre>";
?>
My route
Route::get('/tr', function () {
return view('index');
});
Route::get('/tr/sonuc', function () {
return view('results');
});
Route::post('/tr/sonuc', [App\Http\Controllers\SorgulaController::class, 'sorgula']);
This is the result i got
When i use vanilla php there are domain records. But there is no record when i use Laravel.
Why is that?
I was successful when using process on laravel
<?php
use Symfony\Component\Process\Process;
...
$current = new Process('whois google.com');
$current->run();
if (!$current->isSuccessful()) {
// throw new ProcessFailedException($current);
}
$current = $current->getOutput();
I just found the answer the reason why my shell_exec or exec command doesnt work, it beacuse in my Centos panel there is no 43 port number. When i open port 43 it worked. Just add port number 43 and restart the firewall, it will work after that. Thanks for the answers.
I created a model and its migration like this:
php artisan make:model Lala -m
And I made this : php artisan migrate
I was going to call this road, but I have a mistake. Did I write it wrong? How can I call the search method when my form is submitted?
formular:
<?php
use App\Models\Lala;
?>
<form action="{{ route('Lala.search')}}" method="GET" >
<div class="input-group mb-3">
<input type="text"
name="name" class="form-control" placeholder="Geben Sie etwas an"
aria-label="Geben Sie etwas an"
aria-describedby="basic-addon2" autocomplete="off">
<div class="input-group-append">
<span class="input-group-text" id="basic-addon2">🎓</span>
</div>
</div>
<input type="submit" class="btn btn-primary" value="search">
</form>
I defined the route as follows in web.php :
use App\Models\Lala;
Route::get('/search',[
'as' =>'Lala.search',
'uses' =>'\App\Http\Controllers\stipendiensController#search']);
stipendiensController is defined like this:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Stipendien;
class stipendientsController extends Controller
{
public $name;
public function search()
{
return view('seite.Stipendien');
}
}
how to avoid this error? could I write this code differently? I try indeed to enter the data in my search bar and I compare in my database if the value entered in the search bar is there.
Thank you for helping me . Please
Try defineing your route like so:
use App\Http\Controllers\stipendiensController;
Route::get('/search', [stipendiensController::class, 'search'])
->name('Lala.search');
I am trying to insert data into a database. This actually works but whenever the submit button is clicked and the browser goes to the action page, i get a "CLI has stopped working" error resulting in a shut down of the local php server.
Since i have no clue as to why i am getting this problem. I will provide all the code that possibly could lead to this error.
The form:
<form method="POST" action="store">
{{ csrf_field() }}
<label for="title">Title</label>
<input type="text" id="title" name="title">
<label for="url">URL</label>
<input type="text" id="url" name="url">
<input type="submit">
</form>
The controller:
<?php
namespace App\Http\Controllers;
use App\Article;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class AddArticle extends Controller
{
...
public function store(Request $request)
{
$article = new Article;
$article->title = $request->title;
$article->url = $request->url;
$article->save();
}
...
The model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $table = "posts";
protected $fillable = [
'title',
'url',
];
}
The web.php route:
Route::post('/store', 'AddArticle#store');
When the browser goes to /store, i get this CLI stopped working error.
Kind regards
I need to get a value of input to use below, how to do that?
I tried to like this but error says
Undefined variable: name
<div class="col-md-10 col-md-offset-1">
<input id="name" type="text" name="name" />
</div>
<div class="col-md-10 col-md-offset-1">
#php
$nameValue=$_GET['name'];
#endphp
<input id="name2" type="text" name="name2" value="{{$nameValue}}" />
</div>
$nameValue=Request::input('name')
From the blade template you can access the request parameters with the Request facade, you can also print it directly:
{{Request::input('name')}}
In latest versions you can also use:
{{request()->input('name')}}
You have to be aware that your input-values (here "name") ist only available after submitting the form.
If you want to access the form-values before submitting you should take a look at VueJS or any other frontend-framework (React, Angular). Or simply use jQuery.
Therefor you have to use JavaScript if you want to use the input-value before submitting.
Like the others said in the comments, you can access your form-values within your controller and then pass it to your view.
For example (from the documentation):
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function formSubmit(Request $request)
{
$name = $request->input('name');
return view('form', ['name' => $name])
}
}
Now you can use the value within your view:
<input id="name2" type="text" name="name2" value="{{$name}}">
Another possibility would be to "by-pass" your controller and return your view directly from your routes.php:
Route::get('/form-submit', function(){
return view('form');
});
But I'm not sure if this is working and you could access $_GET/$_PSOT directly without using Laravels Request.
You can get inputs array from Request class:
Request::all()['your_input']
Also you can check if that input you want is exists not:
#isset(Request::all()['your_input'])
{{-- your input existed --}}
#else
{{-- your input does not existed --}}
#endisset
I will get MethodNotAllowedHttpException when submitting a form in laravel
HTML file
<form action="{{ action('HomeController#store') }}" method="post">
<input name="_method" type="hidden" value="PATCH">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<input type="submit" name="Submit" value="submit">
</form>
Im my routes.php
Route::post('formaction','HomeController#store')
Controller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
public function store(){
echo 'form submitted';
}
}
Why i will get MethodNotAllowedHttpException in my form action page?
I've refereed some questions related to this,but nothing help me
Even if the form is using the POST method, you are sending the extra param _method which will let the framework know that you want to use that method instead. If you send that extra param then you should set the route accordingly:
Route::patch('formaction','HomeController#store');