dongpang2483 2016-03-11 17:12
浏览 21

Laravel从阵列查询

My users are able to tag other users in a comment, this returns the Username and the following markup:

<span class="atwho-inserted" data-atwho-at-query="@josh"><a href="/profile/joshuaTest" data-type="mentionable" data-id="undefined" data-name="joshuaTest">joshuaTest</a></span>
<span class="atwho-inserted" data-atwho-at-query="@jish"><a href="/profile/jishy" data-type="mentionable" data-id="undefined" data-name="jishy">jishy</a></span>

I'm doing a preg_match on some regex to retreive some data, I would then like to query based on these bits of data. Example:

$matches = array();
$t = preg_match_all('/data-name="(.*?)\"/', $str, $matches);
//I am aware that $t will provide an int of how many matches exist

$matches will give me exact usernames, with these I can query the database.

I would then like to do something like the following in side of a foreach, I am wondering if it's possible to loop this query with the results of the matched usernames

foreach($matches as $match)
    {
        $j = User::whereUsername($match[0,1,2,3 or whatever here (Until it equals $t)])->first();
    }

and then notify the users found by their username via the Notifynder package:

Notifynder::category('userpropped')
    ->from(1)
    ->to(//UserID from above)
    ->url('/notifications')
    ->send();

Essentially, I would like to grab the users from their usernames, take their IDS and loop through them while passing them to the notifynder function

Is this something that I can achieve or have I gone about things in an incorrect fashion?

Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 CARSIM前车变道设置
    • ¥50 三种调度算法报错 有实例
    • ¥15 关于#python#的问题,请各位专家解答!
    • ¥200 询问:python实现大地主题正反算的程序设计,有偿
    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败