Posts by Kayo Bruno • 2,777 points
137 posts
-
0
votes2
answers29
viewsA: How to return the status "success" and other items in array in wordpress in admin-ajax.php
You can use the function wp_send_json_success() function getItems() { $items = array( // Sua lista completa de itens ); // Eu não colocaria o campo "status" recebendo success, pois você pode tratar…
-
2
votes3
answers671
viewsA: Consume an API that requires authentication with Laravel
Yes it is possible, you should do something more or less like this: Install the guzzle library to be able to consume the API. composer require guzzlehttp/guzzle Then you will consume the desired…
-
2
votes2
answers107
viewsA: List Birthday Kids of the Day Using Laravel
Virgilio’s answer should solve your problem, but I’m going to leave my answer with a little differential you might need. Let’s assume you need to list the birthday of the month and day in the same…
-
3
votes3
answers123
viewsA: Compare range of values
You can create a array with all possible values and go through the same and make only one if within the foreach, I believe that it is better to give maintenance and also to understand the code.…
-
0
votes1
answer98
viewsA: How to join fields from a php array
Your idea is almost right, you don’t need to make one if just create a new array to group by IDTICKET passing as an index of array, so the data with the same id will be grouped. $foo = [ […
-
4
votes2
answers376
viewsA: How to rename a remote and same local branch from the remote?
You can also do as follows: $ git branch -m nome_antigo nome_novo # Renomeia o *branch* local $ git push origin :nome_antigo # Deleta o *branch* antigo no repositório remoto (dois pontos + nome do…
gitanswered Kayo Bruno 2,777 -
2
votes1
answer99
viewsA: List user messages logged in using Laravel
You can add a where in your consultation. public function lista () { $mensagens = Auth::user()->mensagens()->where('status', 1)->get(); $title= "Mensagens"; return…
-
1
votes1
answer73
viewsA: GET PHP MYSQL UPDATE
You can do it this way: // Página 1 - Onde tem o formulário // Vamos supor que a URL é: http://localhost/noticia/editar?id=15 <input type="hidden" name="id" value="<?php echo $_GET['id']…
phpanswered Kayo Bruno 2,777 -
1
votes1
answer276
viewsA: How to join specific commits using git rebase -i?
You can reorder your commits and then squash. $ git rebase -i HEAD~3 pick 68a4eed Removendo .env pick 937d30c Limpando Index squash 55ace82 Limpando index…
gitanswered Kayo Bruno 2,777 -
0
votes1
answer67
viewsA: Delete Laravel6x - with Sweetalert2
Controller public function destroy($id) { $model = Atividade::findOrFail($id); $model->delete(); } Route Route::group(['middleware' => ['auth'], 'prefix' => 'Atividades'], function() {…
-
0
votes1
answer26
viewsA: I want to pass some data on $request in a way that does the same when you send something through the form
You can do this using the function merge() of own request. $data = []; $data['id_cliente'] = $sistemas->id_cliente; $data['id_sistema'] = $sistemas->id_sistema; $data['id_versao_atual'] =…
-
1
votes1
answer649
viewsA: How to check if Cpf and cnpj already exist in the database (Pdo Php)
There are several ways to do this, one of them is you create a function to validate any field, with this "generic" function you can take advantage to validate any single field as for example: email,…
-
0
votes1
answer26
viewsA: Add class with Jquery when opening the page
You can do this by renaming the class to each status type. .on{ color:#155724; background-color:#d4edda; border-color:#c3e6cb; position:relative; border:1px solid transparent; border-radius:.25rem}…
-
0
votes1
answer29
viewsA: Redirect user through another variable, keeping my background - PHP
The title of your question is a bit confusing, but if I understand your problem is only with concatenation. The double quotes say to the PHP to start the interpolation and this costs more appeal.…
phpanswered Kayo Bruno 2,777 -
1
votes1
answer49
viewsA: IF and ELSE if the file is PDF or DOCX
You can use the function pathinfo(), with it you will have some information about the file. And one of them is the extension. You can get more information about this function in this link. // Cria…
phpanswered Kayo Bruno 2,777 -
0
votes3
answers343
viewsA: How to view docx and pdf directly in the browser?
You will need to change the header and use the function readfile(). If you are doing your project with some framework, advise you to create a route, if you do not use any, you can create a file…
phpanswered Kayo Bruno 2,777 -
0
votes2
answers91
viewsA: Query Mysql Time Range
You can use "DATE_ADD()" together with "KURDATE()". This function takes 3 parameters, which are: The date that will be modified, the range that can be positive or negative and finally the type of…
mysqlanswered Kayo Bruno 2,777 -
0
votes2
answers192
viewsA: Print Database Data with FOR in Laravel
With the for you must access the position of the item on array before accessing the property. @for ($i = 0; $i <= count($result); $i++) <tr> <td>{{ $result[$i]->nome }}</td>…
-
2
votes1
answer29
viewsA: Scan list and compare with an Array in Javascript
I believe you want to do this when the page loads, so I think this might help you. $(document).ready(function() { var datas_especiais = ["03/01/2020", "05/01/2020"]; $('#lista li…
javascriptanswered Kayo Bruno 2,777 -
0
votes1
answer36
viewsA: How to validate a field that depends on another to be mandatory in Symfony?
I found the answer in stackoverflow in English. Follow the link to the answer: https://stackoverflow.com/questions/30206854/conditional-validation-of-fields-based-on-other-field-value-in-symfony2…
-
0
votes1
answer17
viewsA: Paging problems using Wp_query
Not working properly because you forgot to enter the parameter paged. This parameter tells which page you are on, as it is not informed, on all pages it will show the data of the first page. $paged…
-
1
votes1
answer54
viewsA: Return records from 00 am to date
You can do this using the BETWEEN or the operators >= and <=. I will leave the 2 examples below. // 00h do dia atual $todayMidnight = (new \Datetime('today midnight'))->format('Y-m-d…
-
0
votes1
answer183
viewsA: How to leave each category a color in wordpress?
You can do this using the function get_the_category() in place of the_category(). There’s only one problem and I don’t know if you thought about it, but what if a post belongs to two or more…
-
1
votes1
answer53
viewsA: Query com Laravel
I believe that one of the examples below can help you: # Utilizando a classe DB $users = DB::table('users') ->where('id', '=', 123) ->where(function ($query) { $query->whereNull('flag')…
-
0
votes1
answer401
viewsA: File Path in project
You can pass your request file to import from Excel. Excel::import(new CartVendasImport, $request->file('your_file'));
-
1
votes1
answer151
viewsA: use redirect to specific page after validation in case of error - Laravel
The class FormRequest has special properties for redirecting, if it does not find any value it uses the default redirect Illuminate\Routing\UrlGenerator::previous(). You can redirect using any of…
-
2
votes1
answer44
viewsA: Eloquent returning JSON as variable
To share any information with all Views you need to use the View::share() in the method boot() of AppServiceProvider or any ServiceProvider that you have created. #AppServiceProvider.php /** *…
-
0
votes1
answer36
viewsQ: How to validate a field that depends on another to be mandatory in Symfony?
In Laravel there is a validation required_if, I say that a field will be mandatory only if another field is informed. I need to do the same type of validation using the FormType from Symfony but I…
-
1
votes2
answers267
viewsA: Add values for same-day array
You can do it by making two foreach and in the second you add up using the $key. $arr = [ 10 => [ '11/06' => 104, '18/06' => 145, '25/06' => 136, '02/07' => 135, '09/07' => 122,…
-
1
votes1
answer41
viewsA: How do I check if a file exists on my hard drive using php? (Linux)
This happens because the function file_exists check if a file or directory exists. And as you said the folder exists but is empty, the function will always return true. To solve this just use the…
-
4
votes1
answer57
viewsA: Doubt with variables and display in the list with PHP
If I understand correctly you want to display the data returned from the database in your table at html, so I think the code below might help you. <?php //chama o arquivo que faz a conexão com o…
-
2
votes1
answer20
viewsA: Execute variable contained function name (PHP)
The $this is a Pseudo-variable of PHP, it works different from other variables, and who manipulates it is the virtual machine of PHP. The $this points to an object in memory, that is, the object…
-
0
votes1
answer88
viewsA: Problem in JSON request - API - json_decode
If I understand correctly you want to create a array only with the product codes. Then the code below should help you to do this. $json_file = file_get_contents('produtos.json', true); $codigos =…
-
0
votes1
answer24
viewsA: Error displaying value saved in $_SESSION in header
The way you did the assignment will not work because you are making a condition. Remove the && and make assignment as in the example below. $_SESSION['nome'] = $nome; $_SESSION['senha'] =…
-
7
votes1
answer88
viewsQ: What is the advantage of PHP objects being passed by default references?
From PHP 5 an object variable no longer contains the object itself as a value. It contains an object identifier that allows the object’s "accessors" to find the real object. I recently went through…
-
2
votes2
answers1554
viewsA: Add hours as Moment.Js
You can calculate the difference in minutes between the "two hours" and then add the difference in the new time. // hora inicial var hrStart = '10:00'; // hora final var hrEnd = '11:02'; // hora que…
-
2
votes5
answers12763
viewsA: PHP - Transforming object into array
You can use the function get_object_vars it returns all public properties of a given object in the format of array associative. $foo = get_object_vars($object); var_dump($foo); // Resultado array(3)…
-
0
votes4
answers1204
viewsA: Laravel - Function in Controller
I refactored your code and managed to wipe the 2 methods in only 1, I hope it helps you. public function gerar(Request $request) { $fields = $request->all(); foreach ($fields['participantes'] as…
-
0
votes1
answer41
viewsA: How to change JWT payload in Laravel?
I was able to solve it this way: Model User use Tymon\JWTAuth\Contracts\JWTSubject; // Meu model agora implementa o JWTSubject class User extends Authenticatable implements JWTSubject{ // Adicionei…
-
0
votes1
answer41
viewsQ: How to change JWT payload in Laravel?
I need to change my payload of my JWT to match the example below. { "iat": 1566408228, "exp": 1566426828, "email": "[email protected]", "name": "Fulano Silva", "roles": [ "manager" ] }…
-
0
votes2
answers57
viewsA: Sorting with multidimensional array
You can sort this using the function usort. Just create a comparison function to pass as a parameter to the function usort. function sortByOrder($a, $b) { return $a['mes'] - $b['mes']; } // Passa o…
phpanswered Kayo Bruno 2,777 -
3
votes1
answer72
viewsA: Capture Json Array with Javascript
I advise you to improve your json, in the javascript every associative array is an object so it gets a little complicated to treat the information the way you set up the json, it’s possible but it’s…
-
1
votes1
answer74
viewsA: Filter using combobox
I believe the solution below will solve your problem, but I suggest you do some validations. $parametro_ano = filter_input(INPUT_GET, "parametro_ano"); $parametro_mes = filter_input(INPUT_GET,…
-
1
votes1
answer80
viewsA: Check if number with isNaN does not work
The way you are doing it won’t really work, in the comments other colleagues have already explained why, so I created the function below to try to help solve your problem. function…
-
4
votes4
answers333
viewsA: How to manipulate these objects with Javascript?
Creates a constructor function to populate the items of your object. var items = {}; var indice = []; var data = [ { letter: "A", num1: "1", num2: "2", num3: "3" }, { letter: "B", num1: "3", num2:…
-
0
votes1
answer30
viewsA: How to validate Insert with relationship
You can use a Form Request customized. // Para criar um `Form Request` execute o comando abaixo: php artisan make:request CreateBrandRequest Form Request: class CreateBrandRequest extends…
-
0
votes1
answer192
viewsA: Call to a Member Function Pluck() on null
The mistake happened because the $user->roles returned null, that is, apparently this user has no relationship with Role. I suggest you take a treatment before using the method pluck(). public…
laravelanswered Kayo Bruno 2,777 -
1
votes2
answers110
viewsA: How to update a table with an array in the Laravel?
One option would be to use mass association of the Laravel. This way it is not necessary to "set" all fields one by one. // Pega todos os campos da request $formData = $request->all(); //…
-
0
votes1
answer46
viewsA: How to get fast Wordpress data using wpdb->get_results
You can make this query using Wp_query $args = array( 'post_type' => 'arquivos', 'post_status' => array('publish'), 'meta_query' => array( array( 'key' => 'tipo', 'value' => 'lanche',…
-
1
votes2
answers273
viewsA: How to insert value in BD only if it does not exist, using Laravel
You can use a if as follows: $data = $request->all(); // Só vai entrar no if se ele encontrar algum registro if (!$user = User::where('email', $data['email'])->first()) { $user =…