Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

mvnobrega

mvnobrega

Member Since 10 Months Ago

Experience Points
4,480
Total
Experience

520 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
4,480 XP
Nov
19
5 days ago
Activity icon

Replied to Search For Accented Words

'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
Activity icon

Started a new Conversation Search For Accented Words

I have the following code to search:

$resultContato = Contato::where(function ($q) use ($terms) {
                
          foreach ($terms as $key) {
                $q->orWhere('nome', 'like', "{$key} %"); 
                $q->orWhere('nome', 'like', "{$key}: %");  
                $q->orWhere('nome', 'like', "% {$key} %");
                $q->orWhere('nome', 'like', "% {$key}");
                $q->orWhere('nome', 'like', "%{$key}");
          }
        })->get();

It works well if the search is done with mixed or capitalized words. However it does not work with accented words.

Even if I remove the accent when searching, still no results are returned.

How can I solve this?

Nov
03
3 weeks ago
Activity icon

Replied to How To Hide The Props

The point is that my esoteric tarot has 157 variables that are generated dynamically when a user clicks on the card. So the result displayed is not the problem. What I don't want to display is the 157 variables that are included in the translation file. Because if they see the whole file, they can do something similar

Activity icon

Replied to How To Hide The Props

so the best solution would be to store it in the database, right?

Activity icon

Started a new Conversation How To Hide The Props

I receive some translation data regarding an esoteric tarot through props. But I would like to hide this information, as I don't want the competition to be able to identify how I generate the tarot results.

Currently I do this:

<tarot :lang="{{ json_encode(__('tarot')) }}"></tarot> 

Is there any way to hide this from the source code?

If not, how could I get the translation data from laravel without it being exposed in the code?

Oct
26
4 weeks ago
Activity icon

Started a new Conversation How To Guarantee Only One Record In The Database

After passing validation, I need to ensure that the data is saved only once. I need to guarantee this, because in some cases 2 or more records are saved even preventing this in the frontend with javascript.

My controller looks like this:

public function salvarRelato(Request $request) {

        $rules = [
        'titulo' => 'required|string|min:4|max:60',
        'sonho' => 'required|string|min:20',
        ]; 

        $messages = [
            'required' => 'Campo obrigatório',
            'titulo.min' => 'O título deve ter entre 4 e 60 caracteres.',
            'titulo.max' => 'O título deve ter no máximo 60 caracteres.',
            'sonho.min' => 'O relato deve ter no mínimo 20 caracteres.',

        ];

        $this->validate($request, $rules, $messages);


        $novo = new Relato;
        $novo->grupo_id = $request->id;
        $novo->user_id = \Auth::user()->id;
        $novo->lang = 'pt-br';
        $novo->titulo  = $request->titulo;
        $novo->slug = mt_rand(1000000, 9999999).'-'.str_slug($novo->titulo, '-');
        $novo->relato = $request->sonho;
        $novo->resumo = $request->resumo;
        $novo->lastMsg = \Auth::user()->username;
        $novo->q1 = $request->q1;
        $novo->q2 = $request->q2;
        $novo->q3 = $request->q3;
        $novo->q4 = $request->q4;
        $novo->q5 = $request->q5;
        $novo->q6 = $request->q6;
        $novo->q7 = $request->q7;
        $novo->q8 = $request->q8;
        $novo->q9 = $request->q9;

        $novo->chakra1 = $request->ck1; 
        $novo->chakra2 = $request->ck2; 
        $novo->chakra3 = $request->ck3; 
        $novo->chakra4 = $request->ck4; 
        $novo->chakra5 = $request->ck5; 
        $novo->chakra6 = $request->ck6; 
        $novo->chakra7 = $request->ck7;
        $novo->exist = $request->exist; 

        $novo->save()

How can I check again if the validation was successful and ensure that the restriction is saved only once in the database?

Oct
20
1 month ago
Activity icon

Started a new Conversation How To Set Canonical Url To Another Language

I have a multi-language website in which only two versions will be identified in content: pt-br and pt

When users access the path "pt" I need to set the canonical url to "pt-br" to prevent google from seeing duplicate content.

But I don't know how to do this.

I could only think about it:

@if(app()->getLocale() === 'pt')
    <link rel="canonical" href="{{Request::url()}}" />
    @endif

But this returns the url of the "pt" pages. How could I change from "pt" to "pt-br"?

Oct
18
1 month ago
Activity icon

Replied to Inserting More Than One Record Improperly

Any suggestion ?

I need to resolve this urgently.

Oct
17
1 month ago
Activity icon

Started a new Conversation Inserting More Than One Record Improperly

My website users complete a personality test that is stored in a database. However, even preventing the user from entering more than one record, in some cases there are users who can send more than one.

I really don't understand the reason for this, because when the user clicks publish once, the save action is removed from the button.

Look my button:

<button  class="btn btn-green" @click="clicouSave ? '' : salvarRelato()"><span>Publicar</span></button>

My data and function:

data(){
            return {
                clicouSave: false,
  }
},


salvarRelato(e) {
                this.clicouSave = true;
                this.relato.loading = true;
                axios.post('/sonhos/novo', {
                    id: this.grupoid,
                    titulo: this.relato.titulo,
                    sonho: this.relato.sonho,
                    resumo: this.relato.resumo,
                    ck1: this.relato.ck.c1,
                    ck2: this.relato.ck.c2,
                    ck3: this.relato.ck.c3,
                    ck4: this.relato.ck.c4,
                    ck5: this.relato.ck.c5,
                    ck6: this.relato.ck.c6,
                    ck7: this.relato.ck.c7,
                })
                .then(response => {
                   
                })
                .catch( error => {
                    this.clicouSave = false;
     
                });  
            },

That is, when the user first clicks "Publicar", clicouSave is set to true and consequently the button stops calling the salvarRelato() function.

In practice this works perfectly. But for some reason some users are managing to send more than one.

Can anyone tell me why this is happening?

Oct
14
1 month ago
Activity icon

Started a new Conversation Prevent White Space In The Input Not Working

I need to prevent my users from placing the "username" with spaces between words.

I solved it this way:

<input @keydown.space.prevent type="text" v-model:value="username">

But @keydown.space.prevent doesn't work on mobile devices or when the user copies and pastes a text.

What better way to solve this?

Oct
11
1 month ago
Activity icon

Started a new Conversation How Remove Update_at Automatic

I have a forum where there is a visit counter, however, the topics are sorted by the updated_at column, so that the user enters the topic, the number of views is increased by +1. and this ends up updating the updated_at column, changing the display order unnecessarily.

I found this solution ($relato->timestamps = false;):

$relato = Relato::where([
                            ['slug', $titulo], 
                            ['grupo_id', $grupo->id]
                        ])->first();


              $Key = 'relato_' . $relato->id;
              
                if (!\Session::has($Key)) {
                
                $relato->timestamps = false;
                $relato->increment('views', 1);

                  \Session::put($Key, 1);
                }

This works in a way, but when I enter the topic I end up getting this error: Call to a member function format() on string

I need to continue using the data in the created_at and updated_at column, but not change the date when I call $report->increment('views', 1);

How could I do that?

Activity icon

Replied to How To Remove App.js From The Cache?

Yes, I use npm run prod on my personal computer. Then, I access the app.js file on my personal computer and copy the code (ctrl + c), go to the hosting service, click on edit the app.js file and paste (ctrl + v) my new code.

Then I save. But when I enter the site the change does not occur, so I need to rename the app.js file, and finally everything works again.

Oct
10
1 month ago
Activity icon

Replied to How To Remove App.js From The Cache?

I do not upload, just change what I need and save directly to the hosting. Then just rename

Activity icon

Replied to How To Remove App.js From The Cache?

Strange, because I clear the browser's cache, tested it on other devices and cell phones, and even in anonymous mode the file is displayed

I change the code and rename it, so the old one ceases to exist.

Activity icon

Started a new Conversation How To Remove App.js From The Cache?

I have already contacted the support of my hosting service believing that the problem was with them, but everything indicates that the laravel itself is creating a cached app.js file.

I had to rename the file for the code changes to take effect on the website.

For example, if you enter this link: https://www.meempi.com/js/app.js

You will see that the app.js file is displayed, but it no longer exists, it has been deleted.

For every adjustment I make to the code, I need to rename the file. Is the laravel really doing this?

How do I solve it?

Oct
09
1 month ago
Activity icon

Awarded Best Reply on How To Enable Php Artisan Queue:work On Shared Hosting?

My shared hosting é Hostinger, and i solved it like this: php /home/u216892564/public_html/artisan queue:work --daemon

Activity icon

Replied to How To Enable Php Artisan Queue:work On Shared Hosting?

My shared hosting é Hostinger, and i solved it like this: php /home/u216892564/public_html/artisan queue:work --daemon

Activity icon

Started a new Conversation How To Enable Php Artisan Queue:work On Shared Hosting?

I have read several topics and articles on the internet on the subject, but this is my first contact with Cron Jobs and I am unable to make it work. I need to keep the php artisan queue: work running. In my hosting it has this:

https://prnt.sc/uwhij5

I've tried it in a few ways, but the two most recent were these:

https://prnt.sc/uwhj69

This does not seem to work, as I am not receiving an account verification email.

Can someone help me ?

Activity icon

Started a new Conversation How To Make 9 Digit Counter With Number_format

In a previous topic, I was given the number_format to do what I need. But I couldn't solve it, because I need to invert the data, and I couldn't do it with number_format.

I need to take the total of topics in the forum and generate a 9 digit counter.

For example, if I have 65 topics: 000,000,065 If I have 1322 topics: 000,001,322

And so on.

I was unable to do this using only number_format. Can you help me ?

Activity icon

Started a new Conversation How To Create Counter In 100,000,000 Format

I need to display the number of topics on my forum in the format 100,000,000

That is, if there are 50 topics, the result should be: 000,000,050. And so on

How can I do this?

Oct
08
1 month ago
Activity icon

Awarded Best Reply on How To Get A Result With A Higher Percentage?

I ended up solving it this way:

$idades = [
            'menor18' => 100/$grupo->totalRespostas*$grupo['menor18'], 
            '19a24' => 100/$grupo->totalRespostas*$grupo['19a24'], 
            '25a30' => 100/$grupo->totalRespostas*$grupo['25a30'],
            '31a35' => 100/$grupo->totalRespostas*$grupo['31a35'],
            '36a40' => 100/$grupo->totalRespostas*$grupo['36a40'],
            '41a45' => 100/$grupo->totalRespostas*$grupo['41a45'],
            '46a50' => 100/$grupo->totalRespostas*$grupo['46a50'],
            '51a55' => 100/$grupo->totalRespostas*$grupo['51a55'],
            '56a60' => 100/$grupo->totalRespostas*$grupo['56a60'],
            '61a65' => 100/$grupo->totalRespostas*$grupo['61a65'],
            '66a70' => 100/$grupo->totalRespostas*$grupo['66a70'],
            'maior70' => 100/$grupo->totalRespostas*$grupo['maior70'],
        ];

        $idadeDestaque = array_keys($idades,max($idades));

Thanks for the suggestions.

Activity icon

Replied to How To Get A Result With A Higher Percentage?

I ended up solving it this way:

$idades = [
            'menor18' => 100/$grupo->totalRespostas*$grupo['menor18'], 
            '19a24' => 100/$grupo->totalRespostas*$grupo['19a24'], 
            '25a30' => 100/$grupo->totalRespostas*$grupo['25a30'],
            '31a35' => 100/$grupo->totalRespostas*$grupo['31a35'],
            '36a40' => 100/$grupo->totalRespostas*$grupo['36a40'],
            '41a45' => 100/$grupo->totalRespostas*$grupo['41a45'],
            '46a50' => 100/$grupo->totalRespostas*$grupo['46a50'],
            '51a55' => 100/$grupo->totalRespostas*$grupo['51a55'],
            '56a60' => 100/$grupo->totalRespostas*$grupo['56a60'],
            '61a65' => 100/$grupo->totalRespostas*$grupo['61a65'],
            '66a70' => 100/$grupo->totalRespostas*$grupo['66a70'],
            'maior70' => 100/$grupo->totalRespostas*$grupo['maior70'],
        ];

        $idadeDestaque = array_keys($idades,max($idades));

Thanks for the suggestions.

Activity icon

Replied to How To Get A Result With A Higher Percentage?

@automica

it is a group table, where each row stores the information of a group a specific group. That is, it has ID, the age group columns mentioned before and many other information that I hid to make it easier and cleaner.

But in summary I get the group like this: $grupo = Grupo::where('id', $request->id)->first();

And inside it I have the columns:

  • less18years
  • 19to25
  • 26to30
  • 31to35
  • 36to40
  • more40

Hence I need to calculate the percentage of each column using the equation: {{100/$grupo->totalRespostas*$grupo->column}}

And display only the result with the highest percentage

Activity icon

Replied to How To Get A Result With A Higher Percentage?

But the data is stored on a single line. So I would need to group the columns of that row, not the column of several rows. So groupby will not work in my case

Activity icon

Started a new Conversation How To Get A Result With A Higher Percentage?

I have a questionnaire that stores the ages of all users who answered it. So for each age range, I have a column, for example:

  • less18years
  • 19to25
  • 26to30
  • 31to35
  • 36to40
  • more40

When generating the result of all people who responded, I need to display only the age group with the highest percentage.

I don't know how best to solve this, without filling my blade with @if and @elseif.

The equation I'm using is: {{100/$grupo->totalRespostas*$grupo->19to25}}

But how can I compare all the results and return only the one with the highest percentage? What is the most efficient way to solve this?

Oct
07
1 month ago
Activity icon

Replied to Json_decode Return Null

@click Thanksss :)))

Activity icon

Started a new Conversation Json_decode Return Null

I can't use my json file on @foreach, because json_decode returns null. Look:

My perguntas.json file:

{

"questions": [
    { "ck": ["c1", "c6"], "id": 1, "text": "Você se sente \"desligado\" ou \"aéreo\"?"  },
    { "ck": ["c1", "c2"], "id": 2, "text": "Tem tendências adictas compulsivas " },
    { "ck": ["c1"], "id": 3, "text": "Sente-se abatido e com pouca energia?" },
    { "ck": ["c1"], "id": 4, "text": "Sente-se apreensivo ou ansioso sem motivo aparente?" },

]

}

My Controller:

        $perguntas = file_get_contents(resource_path('lang/pt-br/perguntas.json'));

        $getperguntas =  json_decode($perguntas);

This does not work, as I get NULL. If I print on the screen without doing the decode, my json looks like this: https://prnt.sc/uuw51r

Why doesn't it work and how do I solve it?

Oct
04
1 month ago
Activity icon

Started a new Conversation I Need Help With Math Solution

Friends, I suck at math, and even looking on the internet, I couldn't safely solve my problem.

Because you are more familiar with these types of situations, I think you can help me.

You see, I have a personality test site that has 72 questions.

  • 72 questions
  • 7 Personality type

The individual test result I already solved. But I also need a result from several users in the same category. For example, I want to gather the result of people who are 50 years old, for this to work, I need to make the right equation, so that I receive the result (and the personality type) proportional to a particular group. And I can't solve this equation.

Let's take a real example. The following database structure consists of responses from a group of users:

  • id
  • totalUser
  • question1
  • question2
  • question3
  • .....
  • question72
  • ck1
  • ck2
  • ck3
  • ck4
  • ck5
  • ck6
  • ck7

totalUser would be the number of people who answered the questionnaire. Because of this, each question column can contain a different number, since the answers "YES" is equal to 1, and the answers "NO" is equal to 0.

CK is the personality type, and each time the user submits the questionnaire, if CK1 is given as true, then 1 will be added in this column

To summarize imagine the scenario: 10 people answered the questionnaire:

  • id
  • totalUser = 10
  • question1 = 10
  • question2 = 8
  • question3 = 2 .....
  • question72 = 2
  • ck1 = 5
  • ck2 = 3
  • ck3 = 7
  • ck4 = 2
  • ck5 = 5
  • ck6 = 5
  • ck7 = 6

Therefore, I need to display the result in proportion to the number of people who responded. So that if the result of 10 users gave "CK1" as a personality type, I need to show it as true.

In short, I don't know what calculation to do, multiplication, division, percentage. it may seem simple, but this is very confusing to me, and I am afraid of generating wrong results due to an inappropriate equation.

Can you help me ?

Oct
03
1 month ago
Activity icon

Replied to How To Remove Columns With NULL Using Where

@tray2

Yes, on second thought, it seems like a good alternative. Thank you friend.

Activity icon

Replied to How To Remove Columns With NULL Using Where

@tray2

Yes it sounds like a good one, but isn't it weird to use the group id for each question, instead of grouping it under a single id?

Activity icon

Replied to How To Remove Columns With NULL Using Where

@a4ashraf

public function novoRelato($slug) {

    	$grupo = Grupo::where('slug', $slug)->first();

        $pextra = Pextra::where('grupo_id', $grupo->id)->first();

        $pextra->makeHidden('grupo_id')->toArray();

        $pextra = $pextra->filter(function ($value) { 
            return !is_null($value); 
        });

        return view('novoRelato', compact(['grupo','pextra']));
    }
Activity icon

Replied to How To Remove Columns With NULL Using Where

@a4ashraf

I'm getting this error: Call to undefined method App\Pextra::filter()

Activity icon

Replied to How To Remove Columns With NULL Using Where

@tray2 But I need to relate the questions to a group. If I reorganize the relationship table it is not adequate.

Activity icon

Started a new Conversation How To Remove Columns With NULL Using Where

I have a table where extra questions for a questionnaire will be stored. I need to get only the columns that have questions filled out.

I'm doing this:

public function novoRelato($slug) {

    	$grupo = Grupo::where('slug', $slug)->first();

        $pextra = Pextra::where('grupo_id', $grupo->id)->first();

        $pextra->makeHidden('grupo_id')->toArray();

        return view('novoRelato', compact(['grupo','pextra']));
    }

Data received: {"q73":"Oi, tudo bem ?","q74":"Como vai ?","q75":"Seu sonho foi legal ?","q76":null,"q77":null,"q78":null,"q79":null,"q80":null}

I'm using makeHidden to hide the grupo_id column, as I need to get only the extra questions for a particular group.

The extra questions table has 10 columns ranging from q73 to q80. But not all are filled, so I need to remove the NULL columns from this collection and get only the columns that have information.

How can I do this ?

Oct
02
1 month ago
Activity icon

Replied to How To Convert Birth Date String To Age

@michaloravec

Thanks for the sugestion. But because it is a multi-language site, the date format can also change. May be 05/12/1990 or 05/12/1990

How could I configure this?

Activity icon

Started a new Conversation How To Convert Birth Date String To Age

When the user registers on the website, the date of birth is stored in a string format, like this: 12/05/1990

I need to calculate the age of the user whenever he submits a new post on the site.

I saw that this function exists: STR_TO_DATE(str, format)

But I can't use it in laravel, and I also don't know how I could get the age using STR_TO_DATE(str, format)

How can I do this ?

Sep
27
1 month ago
Activity icon

Started a new Conversation Transition Group With Slice Not Working As Expected

I have a dynamic paging that displays 10 items at a time, but the <transition-group> does not work as expected. While the previous listing disappears, the new one is added to the page, making the behavior a little strange, see: https://prnt.sc/uouuc7

I tried using mode="out-in" and mode="in-out", but that doesn't solve the problem.

I read all the documentation but found nothing to solve it.

Can you help me ?

Activity icon

Started a new Conversation How To Make V-for Display 10 Items At A Time

I have a questionnaire with 60 questions, and I need to display 10 questions at a time.

But, I'm having trouble making it work even though I see some references on the internet.

The way I am doing, each time I click next(), 10 items are added to the v-for, but the previous 10 items remain on the page.

I'm doing this:

<div class="test-questions comp">
                    <div class="question" v-for="q in perguntas['questions']" v-if="q.id <= perpage">
                        <div class="statement">
                            {{q.id}}. {{q.text}}
                        </div>
                        <div class="options yes-no">
                            <div class="caption option yes">Sim</div>
                            <div class="caption option no">Não</div>
                        </div>
                    </div>
                  
                </div>
                <div class="action-row">
                    <button v-if="perpage == 60" @click="salvarRelato()"><span>Publicar</span></button>
                    <button v-if="perpage < 50" @click="previous()"><span>Anterior</span></button>
                    <button v-if="perpage < 50" @click="next()"><span>Próximo</span></button>
                </div>

My data:

props: ['perguntas'],
        data(){
            return {
                perpage: 10,
            }
        },
        methods: {
            next(){
                this.perpage = this.perpage + 10;
            },
            previous(){
		this.perpage = this.perpage - 10;
            },
        }

Can you help me ?

Activity icon

Started a new Conversation How To Get Json File

I need to get the questions.json file that is inside the language folder. In other words, inside lang/pt-br there is the file questions.json.

I need to include the data from this file inside a vuejs component to perform the v-for. However, I tried in a few ways but I was unable to capture this file.

My last attempt went like this:

<novo-relato questions="{{ __('questions.json') }}"></novo-relato>

How do I get this json file?

Sep
26
1 month ago
Activity icon

Replied to How To Get Range Of Columns In Array?

@automica The answers themselves will not be stored, only the personality type. When answering the 60 questions, the calculation will be done at the end and the database will store only the personality.

So there will be no relationship between questions and answers.

As a multi-language site, I only need one place to capture and display these questions according to the user's language

Activity icon

Replied to How To Get Range Of Columns In Array?

@automica It is a personality test, and the responses will be captured with @click and then stored only the test result. So there will be no relationship between questions and answers in the database.

At the moment I just need to display the questions. I'm thinking of creating a single "questions" column, and storing an array of questions in that single column.

But would that be recommended?

Activity icon

Started a new Conversation How To Get Range Of Columns In Array?

I have a table of questions like this:

public function up()
    {
        Schema::create('perguntas', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->string('lang', 5);
            $table->string('q01');
            $table->string('q02');
            $table->string('q03');
            $table->string('q04');
     		....
            $table->string('q58');
            $table->string('q59');
            $table->string('q60');
        });
    }

And I am capturing such questions with axios like this:

mounted() {
            axios
              .get(this.getperguntas)
              .then(response => {
                this.perguntas = response.data;
            })
        },

I need to use v-for to display only the questions, which are the columns from q01 to q60.

How can I do this ??

The controller looks like this:

public function getPerguntas() {

    	$perguntas = Pergunta::where('lang', app()->getLocale())->get();

    	return response()->json($perguntas);
      	         
    }

Any tips ?

Sep
23
2 months ago
Activity icon

Started a new Conversation Anonymous Users After Deleting Account

I have a discussion forum and I want to keep the topics even after the user deletes the account.

So that the photo and username show "Anonymous User".

What is the logic for doing this?

I need suggestions, because I'm having trouble choosing the best path for this problem.

Sep
22
2 months ago
Activity icon

Started a new Conversation Verify Email With Locale

I need to redirect the email verification link to the home page according to the language

I am using a package for routes in several languages. Because of this, I need to pass a parameter in the verification url with the user's language. For example, currently the url is generated like this: http://127.0.0.1:8000/email/verify/9/577bfcfa617d6e7b41e5eb53ac774bb276cbda06?expires=1600823133&signature=056f4fe440c1715376974c4165b6e5bb6e5bb6e5bb5e7bb5bbbf

I need to insert this in this url ?locale=pt-br

So that in the VerificationController.php file, I can redirect to the home page of the user's language.

Example... protected $redirectTo = localized_route('home', $request->locale);

So that in the VerificationController.php file, I can redirect to the home page of the user's language.

Where should I configure to insert this variable ?Locale=pt-br in the Email verification URL?

And how can I capture it in VerificationController.php?

Any suggestion or tip is welcome.

Sep
20
2 months ago
Activity icon

Replied to How To Pick Up As A User's Conversations

Thanks for the suggestions.

But I ended up doing it like this...

Model User:

public function deUser()
    {
        return $this->hasMany('App\Conversation','de_user_id');
    }

    public function paraUser()
    {
        return $this->hasMany('App\Conversation','para_user_id');
    }

    public function conversations()
    {
        return $this->deUser()->union($this->paraUser()->toBase())->orderBy('updated_at', 'desc');
    }

Model Conversations:

public function deUser()
	{
	  return $this->belongsTo('App\User', 'de_user_id');
	}

	public function paraUser()
	{
	  return $this->belongsTo('App\User', 'para_user_id');
	}

My Blade:

@foreach(Auth::user()->conversations as $c)

                    @if($c->deUser->username !== Auth::user()->username)
                        <a href="{{localized_route('chat', $c->deUser->username)}}" class="conversation ">
                            <div class="avatar"><img src="{{$c->deUser->avatar}}"></div>
                            <div class="info">
                                <div class="name ">
                                    {{$c->deUser->username}}
                                </div>
                                <div class="body">
                                    Howdy! Hows it going?
                                </div>
                            </div>
                            <div class="date"><span aria-hidden="true" class="fas fa-circle"></span> 3 months ago
                            </div>
                        </a>
                    @endif

                    @if($c->paraUser->username !== Auth::user()->username)
                        <a href="{{localized_route('chat', $c->paraUser->username)}}" class="conversation ">
                            <div class="avatar"><img src="{{$c->paraUser->avatar}}"></div>
                            <div class="info">
                                <div class="name ">
                                    {{$c->paraUser->username}}
                                </div>
                                <div class="body">
                                    Howdy! Hows it going?
                                </div>
                            </div>
                            <div class="date"><span aria-hidden="true" class="fas fa-circle"></span> 3 months ago
                            </div>
                        </a>
                    @endif

                @endforeach
Sep
19
2 months ago
Activity icon

Started a new Conversation How To Pick Up As A User's Conversations

I'm having trouble capturing all the messages that the authenticated user has. Look:

Conversations table:

public function up()
    {
        Schema::create('conversations', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->integer('de_user_id')->unsigned();
            $table->foreign('de_user_id')->references('id')->on('users');
            $table->integer('para_user_id')->unsigned();
            $table->foreign('para_user_id')->references('id')->on('users');
            $table->timestamps();
        });
    }

Messages table:

public function up()
    {
        Schema::create('messages', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->integer('conversation_id')->unsigned();
            $table->foreign('conversation_id')->references('id')->on('conversations');
            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users');
            $table->text('message');
            $table->timestamps();
        });
    }

As I'm doing in Controller

public function msgs(Request $request) {

      $conversas = Conversation::where('de_user_id', $request->user()->id)
                   ->orWhere('para_user_id', $request->user()->id)->with(['deUser','paraUser'])->get();


      return view('msgs', compact('conversas'));
        
    }

Conversations Model:

class Conversation extends Model
{
	public function deUser()
	{
	  return $this->belongsTo('App\User', 'de_user_id');
	}

	public function paraUser()
	{
	  return $this->belongsTo('App\User', 'para_user_id');
	}
}

This is all too confusing. Because I need to check de_user_id and para_user_id, because the values depend on who starts the chat.

And the solutions I have been thinking are too exaggerated, as I simply need to show the chats that the authenticated user is part of, like this: https://prnt.sc/ukc4kt

The way I'm doing it doesn't seem to be the best solution, because when it comes to displaying the conversations, I need to check whether de_user_id or para_user_id correspond to the authenticated user so that the username of the sender is displayed and not of the user.

Can you give me a cleaner and simpler solution?

Activity icon

Replied to ->each Function With Relationship

I understand what's going on, buddy.

I'm using the package: chinleung / laravel-multilingual-routes

And I didn't define the Api route to use it, so it didn't return the correct language.

Now I managed to solve it.

Thank you very much for your attention.

(Y)

Activity icon

Replied to ->each Function With Relationship

Does not work!

It always returns en, and the request was made in pt-br