Posts by David Santos • 810 points
33 posts
-
2
votes1
answer331
viewsA: Validate non-mandatory fields using Laravel Validation 5.8
Just add the nullable in front: public function rules() { // dd('ok'); return [ 'email' => 'nullable|email' ]; } https://laravel.com/docs/5.8/validation#Rule-nullable…
-
1
votes2
answers283
viewsA: PHP constructors
The only way to use the methods of a class without instantiation is if they are static. Example: class User { public static function create($data) { // code here } } And to use it:…
-
5
votes1
answer622
viewsA: Get the login user id
To catch the id of the logged-in user: Auth::user()->id This if you are using the guard which comes by default.
-
0
votes1
answer68
viewsA: Error when trying to enter form in the authenticated user’s Language (foreign key to another table)
If the field user_id is not explicitly defined in the view it will not be populated, that is, it is not automatically injected. You can do it like this: <input type="hidden" name="user_id"…
-
1
votes1
answer27
viewsA: Query in more than one mysql column with PHP
You can add the conditions and and or. Example: $sql = $conn->prepare("SELECT * FROM empresas WHERE nome LIKE ? and palavras-chaves LIKE ?"); or $sql = $conn->prepare("SELECT * FROM empresas…
phpanswered David Santos 810 -
0
votes1
answer22
viewsA: Shouldn’t queries be executed in a view?
As per standard MVC your queries should be executed by the layer Model. The MVC is a very popular and widely applied standard these days. It is a standard and can be replaced by others. However it…
phpanswered David Santos 810 -
1
votes3
answers109
viewsA: Run Ajax script automatically
You can use the event onblur similar to the way you used the onkeyup. Example: <input type="text" name="cep" id="cep" onkeyup="maskIt(this,event,'#####-###')" onblur="buscaCep()"/> The event…
-
0
votes1
answer64
viewsA: How to Create a Truly Global Scope
You could put for class Model inherit Scope, but that would entail changing something on the basis of Framework, which could entail future updates. Then I recommend the following: Create a class to…
laravelanswered David Santos 810 -
2
votes1
answer53
viewsA: Differences between ways to reference a namespace
In that case there is no difference. But imagine the following scenario: You have the class App\User and the class Services\User. namespace App\User; public function teste() { $services = new…
-
1
votes1
answer421
viewsA: Coupon-style PDF size
You can pass the paper size as follows: ->setPaper([0, 0, 807.874, 221.102], 'landscape')
-
0
votes0
answers124
viewsQ: Error in content type Guzzle
I am using this trait as the basis of the request and am setting the Content-Type as application/vnd.api+json trait BaseRequest { private static $url = 'url'; public static function request() {…
-
1
votes1
answer57
viewsQ: Transaction in different banks
In a certain part of the system I need to do the transaction control, but this operation involves tables that are in different databases. I made a test by inserting two tables in different banks and…
-
1
votes3
answers2817
viewsA: How to identify the error in PHP code by Chrome?
PHP is interpreted by the web server (apache, Nginx) and its response is delivered to the caller (browser, ajax). To view any errors that may occur you must enable the display of PHP errors in the…
-
2
votes1
answer2525
viewsA: Middleware Laravel Group Authentication
You can define a group of routes and add middleware this way: Route::middleware('auth')->group(function () { Route::middleware('Check')->group(function () { // Rotas que só o admin pode…
-
1
votes1
answer155
viewsA: How to pass javascript return to php variable
You can do this with a request via ajax for PHP. For example : $.ajax({ url : 'caminho-arquivo-php', type: 'get' // método http, como : put, post, delete .... success: function (dados) { //…
-
1
votes1
answer34
viewsA: Can you define the type of variables in the parameters of a method?
You can define whether the type is array or object. In PHP 7 this feature has been extended, and today you can use it with int, float and the like. To use this feature is very simple. Example:…
phpanswered David Santos 810 -
0
votes2
answers124
viewsA: Rollback problems on Laravel 5.5
To capture the exceptions generated by the bank use \PDOException, to \Exception does not capture this type of error. Possibly as the error is not being captured the transaction occurs normalmente.…
-
2
votes1
answer142
viewsA: Generate image with initials of name, same as Hotmail, Skype, Gmail
You could do it this way, using the function explodes and catching the 1 character of the first and second array $array = explode(" ", $nome); $iniciais = $array[0][0] . $array[1][0]; For sending a…
phpanswered David Santos 810 -
2
votes1
answer29
viewsA: Go to a new view with Json
Put it that way : window.location.href= 'rota'
-
1
votes1
answer73
viewsA: Request problem via ajax
Has a if checking that the message is equal to ERROR, but there is no action if it is different from that. You can put a window.location.href='pagina que deseja'. You won’t be able to redirect with…
-
1
votes2
answers399
viewsA: Problems passing URL parameter
You can add a click event to this button and do a function with javascript to concatenate the input values with the url, for example : <button onclick="produtosObras()" id="btnUrl"…
-
3
votes2
answers343
viewsQ: How to clone a second branch using the same directory as the first cloned branch?
I have a repository with several branches, cloned a specific one and worked on it. Later the need to work on another branch of this same project arose, has how to clone it to the same folder of the…
gitasked David Santos 810 -
1
votes3
answers220
viewsA: show html page in php
as already mentioned, headers cannot be sent after the output, so if you do not perform any output, you can use this function to redirect to another page : header('Location: main.html');…
-
2
votes1
answer1751
viewsQ: Validation in the Laravel
I’m wearing a Form Request Validation to validate a form, but when I leave a field of the typerequired blank no error is generated. How do I generate an error when validation fails ? class…
-
1
votes1
answer330
viewsQ: Mass Attribution in Laravel
use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; class Sale extends Model { protected $guarded = ['id']; public function vendor() { return $this->hasMany('App\Vendor');…
-
6
votes4
answers1424
viewsA: How to continue incrementing the value of a variable even after a page is reloaded?
The script stores the values of the variables only at runtime, after which the space in the memory occupied by them is released. Every time you refresh the page the script goes back to its original…
phpanswered David Santos 810 -
0
votes1
answer236
viewsQ: Very large input fields
When copying and pasting a simple code from an example form on the bootstrap website, the following occurs: Why are these fields like this ? According to the example they should be much smaller.…
twitter-bootstrapasked David Santos 810 -
0
votes2
answers46
viewsA: How to join edit/new button?
I believe the countryside $name in this Insert should be $Nome. And a mysqliquery was missing right after the Insert: if ($result == 0) { $query = "INSERT INTO Medicos (nome, NIF, telemovel,…
-
0
votes2
answers165
viewsQ: Order of execution of unit tests
Is there any way to define the order of execution of the test methods ? When I put the function code testSelectDaInsercao inside testInsercaoDeDados the tests are executed successfully, but this way…
phpasked David Santos 810 -
1
votes1
answer353
viewsQ: How to perform mock in a class?
I created this script for testing purposes, and I have a class Calculadora which takes a class instance as a parameter Operacao, when performing the unit test passing the class the test occurs…
-
0
votes1
answer40
viewsQ: Duplicate data in response to a query
That is the code : $conn = new PDO('mysql:host=localhost;dbname=locadora','root',''); $resul = $conn->query("SELECT * FROM usuario"); echo "<pre>"; $resul = $resul->fetchAll(); ?> And…
-
0
votes1
answer69
viewsQ: Lasso
whereas the "users" table does not exist, catch be executed, the "errors" function is executed Code : <?php $usuario = 'root'; $senha =''; function errors($e) { echo "Erro dados"; }…
phpasked David Santos 810 -
7
votes2
answers174
viewsQ: Doubt in recursive function
When I put: return n * fatqua(n-1) the program returns the expected result that is 24. But when I put: return n * fatqua(--1) the result of the program is 0. I’m not getting the logic of this…